local extension = Package("rfenghou_jisicup")
extension.extensionName = "aaa_fenghou"

local U = require "packages/utility/utility"
local RUtil = require "packages/aaa_fenghou/utility/rfenghou_util"
local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["rfenghou_jisicup"] = "祭赛",
  ["rfenghouif"] = "if",
}

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

-- 南宫杯
local rfenghou__zhangbu = General:new(extension, "rfenghou__zhangbu", "wu", 4)
Fk:loadTranslationTable{
  ["rfenghou__zhangbu"] = "张布",
  ["#rfenghou__zhangbu"] = "浮浮沉沉",
  ["designer:rfenghou__zhangbu"] = "屑",
  ["cv:rfenghou__zhangbu"] = "妙啊",
  ["illustrator:rfenghou__zhangbu"] = "哥达耀",

  ["$rfenghou__zhangbu_win_audio"] = "身佩大印，女得大贵，张家自此兴旺！",
  ["~rfenghou__zhangbu"] = "虽有前功，弗克其终，帝今亦然，臣死必矣...",
}

local buju = fk.CreateActiveSkill{
  name = "rfenghou__buju",
  mute = true,
  anim_type = "control",
  min_target_num = 1,
  prompt = "布局：选择任意名角色，视为对他们使用【五谷丰登】。",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  card_filter = function (self, to_select, selected)
    return false
  end,
  target_filter = function (self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return not to:isNude()
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local tos = effect.tos
    player:broadcastSkillInvoke(self.name, math.random(2))
    room:sortPlayersByAction(tos)
    local tos2 = {}
    for _, pid in ipairs(tos) do
      local p = room:getPlayerById(pid)
      table.insertIfNeed(tos2,p)
      if not p:isNude() then
      local cids = room:askForCard(p,1,1,true,self.name,false,".","布局：请将一张牌置于牌堆顶")
      if #cids>0 then
        room:moveCards({
          ids = cids,
          from = pid,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
        })
      end
      end
    end
    if not player.dead then
      tos2 = table.filter(tos2, function (p)
        return not p.dead
      end)
      room:useVirtualCard("amazing_grace", {}, player, tos2, self.name)
    end
  end,
}
local buju_aftereffect = fk.CreateTriggerSkill{
  name = "#rfenghou__buju_aftereffct",
  events = {fk.AfterCardsMove},
  mute = true,
  on_cost = function (self, event, target, player, data)
    return true
  end,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill("rfenghou__buju") then
      local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if use_event then
        local use = use_event.data[1]
        if use.card.trueName == "amazing_grace" and use.from == player.id and use.card.skillName == "rfenghou__buju" then
          for _, move in ipairs(data) do
            if move.toArea == Card.Processing and move.moveReason == fk.ReasonPut and #move.moveInfo>0 then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = {}
    local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if use_event then
      local use = use_event.data[1]
      if use.card.trueName == "amazing_grace" and use.from == player.id  and use.card.skillName == "rfenghou__buju"  then
        for _, move in ipairs(data) do
          if move.toArea == Card.Processing and move.moveReason == fk.ReasonPut then
            for _, info in ipairs(move.moveInfo) do
                table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      if #cards > 0 then
        local slashnum = 0
        local othernum = 0
        for _, cid in ipairs(cards) do
          local c = Fk:getCardById(cid)
          if c.trueName == 'slash' then
            slashnum = slashnum+1
          else
            othernum = othernum+1
          end
        end
        if slashnum > othernum then
          player:broadcastSkillInvoke("rfenghou__buju", 3)
          local num = 0
          while num < slashnum and not player.dead do
          local use = U.askForUseVirtualCard(room, player, "slash", nil, self.name, "布局：你可以视为使用一张【杀】", true, true, false, true, nil, true)
        if use then
          room:handleAddLoseSkills(player, "-rfenghou__buju", nil, true, false)
          room:setPlayerMark(player, "rfenghou__buju_toget", 1)
          use.extraUse = true
          room:useCard(use)
          num = num+1
        else
          break
        end
      end
        else
          player:broadcastSkillInvoke("rfenghou__buju", 4)
          room:loseHp(player,1,self.name)
          if player:isAlive() then
          local to = room:askForChooseToMoveCardInBoard(player, "布局：你可以移动场上的一张牌", self.name, true)
          if #to == 2 then room:askForMoveCardInBoard(player, room:getPlayerById(to[1]), room:getPlayerById(to[2]), self.name) end
          end
        end
      end
    end
  end,
}
local shunyi = fk.CreateTriggerSkill{
  name = "rfenghou__shunyi",
  mute = true,
  events = {fk.HpChanged},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and #player.room:getBanner("@$CenterArea") > 0 then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = U.askforChooseCardsAndChoice(player, player.room:getBanner("@$CenterArea"), {"OK"}, self.name,
      "顺意：是否秘密选择中央区的一张牌", {"Cancel"})
    if #cards > 0 then
      self.cost_data = cards[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, math.random(2))
    local tos = table.map(room:getOtherPlayers(player),Util.IdMapper)
    if #tos > 0 then
      local to = room:askForChoosePlayers(player,tos,1,1,"顺意：令一名其他角色获得中央区的一张牌",self.name,false)
      if #to>0 then
        local totarget = room:getPlayerById(to[1])
        local get = room:askForCardsChosen(totarget, totarget,1,1, {
          card_data = {
            { "中央区", room:getBanner("@$CenterArea") }
          }
        }, self.name,"顺意：获得中央区一张牌，不是被秘密选择的牌则你要弃牌")
        if #get>0 then
          room:moveCardTo(get, Player.Hand, totarget, fk.ReasonJustMove, self.name, "", true, to[1])
          if get[1]~=self.cost_data then
            local cards = room:askForDiscard(totarget, 3, 3, true, self.name, false, ".", "#rfenghou__shunyi:"..player.id)
            cards = table.filter(cards,function(cid) 
              local c = Fk:getCardById(cid)
              return room:getCardArea(cid) == Card.DiscardPile and ((c.trueName == "slash") or (c.type == Card.TypeEquip))
            end)
            if table.find(cards,function(cid) 
              local c = Fk:getCardById(cid) return room:getCardArea(cid) == Card.DiscardPile and c.trueName == "slash"
            end) and player:getMark("rfenghou__buju_toget") > 0 then
              room:handleAddLoseSkills(player, "rfenghou__buju", nil, true, false)
              room:setPlayerMark(player, "rfenghou__buju_toget", 0)
            end
            if #cards > 0 then
              player:broadcastSkillInvoke(self.name, 3)
              room:moveCardTo(cards, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
            end
          end
        end
      end
    end
  end,
}
shunyi.CenterArea = true
buju:addRelatedSkill(buju_aftereffect)
rfenghou__zhangbu:addSkill(buju)
rfenghou__zhangbu:addSkill(shunyi)
AddWinAudio(rfenghou__zhangbu)
Fk:loadTranslationTable{
  ['steam_centralarea'] = "其实就是本回合进入过弃牌堆，且仍在弃牌堆内的牌。",
  ["rfenghou__buju"]="布局",
  [":rfenghou__buju"]="出牌阶段限一次，你可令任意名角色各将一张牌置于牌堆顶，视为对这些角色使用【五谷丰登】。亮出牌后，若其中的【杀】大于其余牌，你视为使用至多等量张【杀】并失去此技能，直到下次“顺意”获得【杀】，否则失去1点体力并移动场上一张牌。",
  ["rfenghou__shunyi"]="顺意",
  [":rfenghou__shunyi"]="当你的体力值变化后，你可以秘密选择<a href='tyj_centralarea'>中央区</a>一张牌，令一名其他角色获得<a href='tyj_centralarea'>中央区</a>一张牌。若其未获得选择牌，其弃置三张牌，令你获得其中的【杀】或装备牌。",

  ["#rfenghou__buju_aftereffct"]="布局",
  ["#rfenghou__shunyi"]="顺意：弃置三张牌，%src 获得其中的【杀】和装备牌。",

  ["$rfenghou__buju1"] = "今日召集诸君，有大事相议。",
  ["$rfenghou__buju2"] = "陛下忍辱久矣，明日设宴，正为诛綝良机！",
  ["$rfenghou__buju3"] = "胤，据刀俎加身之苦，汝当同之！",
  ["$rfenghou__buju4"] = "大事已泄，吾率部曲殿后，陛下请退他处！",
  ["$rfenghou__shunyi1"] = "老夫不慎逾礼，请君念某前功，体之谅之！",
  ["$rfenghou__shunyi2"] = "昔日峻、綝曝尸此壑，君何不往泉下谒之？",
  ["$rfenghou__shunyi3"] = "竖子果欲加害，幸有先见之明！",
}

local rfenghou__sunjunsunchen = General:new(extension, "rfenghou__sunjunsunchen", "wu", 4,4)
Fk:loadTranslationTable{
  ["rfenghou__sunjunsunchen"] = "孙峻&孙綝",
  ["#rfenghou__sunjunsunchenn"] = "暂无",
  ["designer:rfenghou__sunjunsunchen"] = "易大剧",
  ["cv:rfenghou__sunjunsunchen"] = "官方",
  ["illustrator:rfenghou__sunjunsunchen"] = "恶童",
}
local feigong = fk.CreateActiveSkill{
  name = "rfenghou__feigong",
  anim_type = "offensive",
  prompt = "沸宫：是否令三对角色依次拼点？",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local can = table.map(table.filter(room.alive_players, function(p) return
      #table.filter(room.alive_players,function(po) return
      po~=p and p:canPindian(po)
      end)>0
     end),Util.IdMapper)
     local toses = {}
      local targets1= room:askForChoosePlayers(player,can,2,2,"沸宫：选择要拼点的角色（1/3）",self.name,false)
      table.insert(toses,targets1)
      local targets2= room:askForChoosePlayers(player,can,2,2,"沸宫：选择要拼点的角色（2/3）",self.name,true)
        if #targets2>1 then
        table.insert(toses,targets2)
        local targets3= room:askForChoosePlayers(player,can,2,2,"沸宫：选择要拼点的角色（3/3）",self.name,true)
        if #targets3>1 then
          table.insert(toses,targets3)
          end
        end
      local lastwin = 0
      for _, tos in ipairs(toses)do
        local p1 = room:getPlayerById(tos[1])
        local p2 = room:getPlayerById(tos[2])
        local thislastwin = lastwin
        if p1:isAlive() and p2:isAlive() and p1:canPindian(p2) then
        lastwin = 0
        local pindian = p1:pindian({p2}, self.name)
      local winner = nil
      local loser=nil
      if pindian.results[p2.id].winner == p1 then
        winner=p1
        lastwin = p1.id
        loser=p2
      elseif pindian.results[p2.id].winner == p2 then
        winner=p2
        lastwin = p2.id
        loser=p1
      else
      end
      if winner and winner:isAlive() then
      local all_choices = {"干上次赢的人","偷没赢的角色的两张牌","取消后续拼点"}
      local choices = {}
      if thislastwin ~=0 and room:getPlayerById(thislastwin):isAlive() then
        table.insertIfNeed(choices,"干上次赢的人")
      end
      if loser and loser:isAlive() and #loser:getCardIds("he")>1 then
        table.insertIfNeed(choices,"偷没赢的角色的两张牌")
      end
      if tos~=toses[#toses] then
        table.insertIfNeed(choices,"取消后续拼点")
      end
      if #choices>0 then
        local res = room:askForChoice(winner,choices,self.name,"沸宫：选择并执行一项",false,all_choices)
        if res == "干上次赢的人" then
          if room:getPlayerById(thislastwin):isAlive() then
            room:damage({
              from = winner,
              to = room:getPlayerById(thislastwin),
              damage = 1,
              damageType = fk.NormalDamage,
              skillName = self.name,
          })
          end
        elseif res == "偷没赢的角色的两张牌" then
          local cards = room:askForCardsChosen(winner, loser, math.min(2, #loser:getCardIds("he")), 2, "he", self.name)
          room:obtainCard(winner, cards, false, fk.ReasonPrey)
        else
          break
        end
      end
    end
    end
    end
  end,
}

rfenghou__sunjunsunchen:addSkill(feigong)
Fk:loadTranslationTable{
  ["rfenghou__feigong"]="沸宫",
  [":rfenghou__feigong"]="出牌阶段限一次，你可以依次选择至多三对角色，然后令每对角色依次拼点。赢的角色须选择一项：1.获得没赢的角色两张牌；2.对上一次拼点赢的角色造成一点伤害；3.取消后续拼点。",
}



-- 公式赛
local chundoohwan = General:new(extension, "rfenghou__chundoohwan", "ghan", 4)

Fk:loadTranslationTable{
  ["rfenghou__chundoohwan"] = "全斗焕",
  ["#rfenghou__chundoohwan"] = "全小将",
  ["cv:rfenghou__chundoohwan"] = "李德华",
  ["designer:rfenghou__chundoohwan"] = "emo公主",
  ["illustrator:rfenghou__chundoohwan"] = "AI",
  ["$rfenghou__chundoohwan_win_audio"] = "今天最高兴了！",
  ["~rfenghou__chundoohwan"] = "被告人全斗焕，死刑。",
}
AddWinAudio(chundoohwan)

local yixin = fk.CreateViewAsSkill{
  name = "rfenghou__yixin",
  anim_type = "offensive",
  prompt = "#rfenghou__yixin",
  card_filter = function(self, to_select, selected, player)
    if not table.contains(player:getHandlyIds(), to_select) then return false end
    local n = player:getHandcardNum()
    if n ~= 1 then n = 3 end
    return #selected < n
  end,
  view_as = function(self, cards, player)
    local n = player:getHandcardNum()
    if n ~= 1 then n = 3 end
    if #cards ~= n then return nil end
    local c = Fk:cloneCard("hanqing__underhanding")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function (self, player, use)
    -- 用于确定使用此牌前哪些目标已经有4种花色，后不会参与“调整至4花色”的结算
    if use.tos then
      use.extra_data = use.extra_data or {}
      use.extra_data.rfenghou__yixinFourSuit = {}
      for _, pid in ipairs(TargetGroup:getRealTargets(use.tos)) do
        local to = player.room:getPlayerById(pid)
        local suits = {}
        local hand = to.player_cards[Player.Hand]
        for _, id in ipairs(hand) do
          table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        if #suits == 4 then
          table.insertIfNeed(use.extra_data.rfenghou__yixinFourSuit, pid)
        end
      end
    end
  end,
  after_use = function (self, player, use)
    local room = player.room
    local tos = {}---@type ServerPlayer[]
    local fourSuit = (use.extra_data or Util.DummyTable).rfenghou__yixinFourSuit or Util.DummyTable
    for _, pid in ipairs(TargetGroup:getRealTargets(use.tos)) do
      if not room:getPlayerById(pid).dead then
        table.insertIfNeed(tos, room:getPlayerById(pid))
      end
    end
    local option1, option2
    for _, to in ipairs(tos) do
      local suits = {}
      local hand = to.player_cards[Player.Hand]
      for _, id in ipairs(hand) do
        table.insertIfNeed(suits, Fk:getCardById(id).suit)
      end
      if #suits == 4 and not table.contains(fourSuit, to.id) then option2 = true end
      if #suits == #hand then
        room:doIndicate(player.id, {to.id})
        option1 = true
        if #suits == 4 then
          local useIds = table.filter(hand, function(id) return not player:prohibitUse(Fk:getCardById(id)) end)
          while not player.dead and #useIds > 0 do
            local touse = room:askForUseRealCard(player, useIds, self.name, "#rfenghou__yixin-use", {expand_pile = useIds}, false)
            if not touse then break end
            useIds = table.filter(useIds, function(id) return table.contains(to.player_cards[Player.Hand], id) end)
          end
        else
          to:throwAllCards("h", self.name)
        end
      end
    end
    if not player.dead and option2 then
      if room:askForSkillInvoke(player, self.name, nil, "#rfenghou__yixin-draw"..(option1 and "use" or "")) then
        player:drawCards(3, self.name)
        if player.dead or player:isKongcheng() then return end
        local x = math.ceil(player:getHandcardNum() / 2)
        if option1 then
          local cards = room:askForCard(player, x, x, false, self.name, false, nil, "#rfenghou__yixin-chooseuse:::"..x)
          while not player.dead and #cards > 0 do
            local touse = room:askForUseRealCard(player, cards, self.name, "#rfenghou__yixin-use", nil, false)
            if not touse then break end
            cards = table.filter(cards, function(id) return table.contains(player.player_cards[Player.Hand], id) end)
          end
        else
          room:askForDiscard(player, x, x, false, self.name, false)
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng()
  end,
  enabled_at_response = Util.FalseFunc,
}
chundoohwan:addSkill(yixin)

Fk:loadTranslationTable{
  ["rfenghou__yixin"] = "一心",
  [":rfenghou__yixin"] = "你可以将三张或唯一手牌当【瞒天过海】使用，然后若使目标手牌花色数：1.等于手牌数，令其弃置所有手牌；2.调整至四，你可以摸三张牌并弃置一半手牌。若均满足，以你使用代替弃置。",
  ["#rfenghou__yixin"] = "一心：将三张或唯一手牌当【瞒天过海】使用，然后根据目标手牌花色数执行后续",
  ["#rfenghou__yixin-use"] = "一心：你须使用这些牌",
  ["#rfenghou__yixin-draw"] = "一心:你可以摸三张牌并弃置一半手牌（向上取整）",
  ["#rfenghou__yixin-drawuse"] = "一心:你可以摸三张牌并使用一半手牌（向上取整）",
  ["#rfenghou__yixin-chooseuse"] = "一心:选择 %arg 张手牌使用",
  ["$rfenghou__yixin1"] = "军人都很单纯的，都是为了为国尽忠而生的。",
  ["$rfenghou__yixin2"] = "他妈的，国家怎么变成了这个样子。",
}

local kongshu = fk.CreateVisibilitySkill{
  name = "rfenghou__kongshu",
  card_visible = function(self, player, card)
    if player:hasSkill(self) then
      local room = Fk:currentRoom()
      local owner = room:getCardOwner(card.id)
      if owner and table.contains(owner.player_cards[Player.Hand], card.id) then
        if owner.hp < player.hp and table.every(room.alive_players, function(p) return p.hp <= player.hp end)
        and table.every(room.alive_players, function(p) return p.hp >= owner.hp end) then
          return true
        end
        if owner:getHandcardNum() < player:getHandcardNum() and
        table.every(room.alive_players, function(p) return p:getHandcardNum() <= player:getHandcardNum() end)
        and table.every(room.alive_players, function(p) return p:getHandcardNum() >= owner:getHandcardNum() end) then
          return true
        end
      end
    end
  end
}
chundoohwan:addSkill(kongshu)
Fk:loadTranslationTable{
  ["rfenghou__kongshu"] = "空输",
  [":rfenghou__kongshu"] = "锁定技，若你手牌/体力最大，手牌/体力最小且小于你的角色手牌对你可见。",
  ["$rfenghou__kongshu1"] = "不能再犹豫了，必须要出重拳。",
  ["$rfenghou__kongshu2"] = "不惧怕空输的威力，已经不是一般老百姓了，这明显全都是暴徒。",
}


local lonecity = General:new(extension, "rfenghou__lonecity", "fuyao", 4)

Fk:loadTranslationTable{
  ["rfenghou__lonecity"] = "孤城万里",
  ["#rfenghou__lonecity"] = "",
  ["cv:rfenghou__lonecity"] = "",
  ["designer:rfenghou__lonecity"] = "yyuaN",
  ["illustrator:rfenghou__lonecity"] = "AI",
  ["~rfenghou__lonecity"] = "",
}

local zongshizz = fk.CreateTriggerSkill{
  name = "rfenghou__zongshizhizao",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return player.phase == Player.Draw and not player:isKongcheng()
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(player, 1, 1, false, self.name, true, nil, "#rfenghou__zongshizhizao-show")
    if #cards == 1 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    player:showCards(cards)
    local num = Fk:getCardById(cards[1]).number
    -- 我直接翻记录器
    local recastNumCheck = function (n)
      return #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.from and move.moveReason == fk.ReasonRecast then
            local recastNum = #table.filter(move.moveInfo, function(info)
              return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
            end)
            if recastNum == n then return true end
          end
        end
        return false
      end, Player.HistoryTurn) == 0
    end
    for _, to in ipairs(room:getAlivePlayers()) do
      if not to.dead then
        local cids = {}
        if not to:isNude() then
          local _, dat = room:askForUseActiveSkill(to, "rfenghou__zongshizhizao_active",
          "#rfenghou__zongshizhizao-recast:::"..num, true, {rfenghou__zszz = num})
          if dat then
            cids = dat.cards
          end
        end
        if #cids > 0 then
          local first = recastNumCheck(#cids)
          room:recastCard(cids, to, self.name)
          if not player.dead and first then
            player:drawCards(1, self.name)
          end
        else
          room:doIndicate(player.id, {to.id})
          room:loseHp(to, 1, self.name)
        end
      end
    end
    return true
  end,
}

lonecity:addSkill(zongshizz)

local rfenghou__zongshizhizao_active = fk.CreateActiveSkill{
  name = "rfenghou__zongshizhizao_active",
  min_card_num = 1,
  target_num = 0,
  card_filter = function(self, to_select, selected)
    local n = Fk:getCardById(to_select).number
    for _, id in ipairs(selected) do
      n = n + Fk:getCardById(id).number
    end
    return n < (self.rfenghou__zszz or 0)
  end,
}
Fk:addSkill(rfenghou__zongshizhizao_active)

Fk:loadTranslationTable{
  ["rfenghou__zongshizhizao"] = "宗师之造",
  [":rfenghou__zongshizhizao"] = "摸牌阶段，你可以改为展示一张手牌，然后所有角色依次失去1点体力或重铸任意张点数和小于此牌的牌，若为本回合首次重铸此数量牌，你摸一张牌。",
  ["#rfenghou__zongshizhizao-show"] = "宗师之造：你可放弃摸牌，展示一张手牌，令所有角色选择失去体力或重铸牌",
  ["#rfenghou__zongshizhizao-recast"] = "宗师之造：重铸任意张点数之和小于 %arg 的牌，否则失去1血",
  ["rfenghou__zongshizhizao_active"] = "重铸",
}

local dubushanhe = fk.CreateTriggerSkill{
  name = "rfenghou__dubushanhe",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if target == player then
        local modenums, map, max = {}, {}, 0
        for _, p in ipairs(player.room.alive_players) do
          local num = p:getHandcardNum()
          map[num] = (map[num] or 0) + 1
          max = math.max(max, map[num])
        end
        for i, num in pairs(map) do
          if num == max then
            table.insert(modenums, i)
          end
        end
        return table.contains(modenums, player:getHandcardNum() + data.num)
      else
        return (target:getHandcardNum() + data.num) == player:getHandcardNum()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target == player then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "drawcard")
      data.num = data.num + 1
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "control", {target.id})
      room:doIndicate(player.id, {target.id})
      room:setEmotion(player, "./packages/aaa_fenghou/image/anim/demonsmile")
      data.num = data.num - 1
      room:sendLog{type = "#MinusDrawNum", from = target.id}
      return data.num < 1
    end
  end,
}
lonecity:addSkill(dubushanhe)

Fk:loadTranslationTable{
  ["rfenghou__dubushanhe"] = "独步山河",
  [":rfenghou__dubushanhe"] = "锁定技，你摸牌前，若会摸至众数，则多摸一张；其他角色摸牌前，若会摸至你的手牌数，则少摸一张。",
  -- 众数是指出现次数最多的数。如果多个数出现的次数相同且都是最多的，那么这些数都是众数。
  ["#MinusDrawNum"] = "%from 摸牌数-1",
  ["$rfenghou__dubushanhe1"] = "", -- 自己多摸牌
  ["$rfenghou__dubushanhe2"] = "", -- 别人少摸牌
}

local yujig = General:new(extension, "rfenghou__yujig", "chu", 3, 3, General.Female)

Fk:loadTranslationTable{
  ["rfenghou__yujig"] = "虞姬",
  ["#rfenghou__yujig"] = "素心不染",
  ["cv:rfenghou__yujig"] = "",
  ["designer:rfenghou__yujig"] = "老酒馆的猫",
  ["illustrator:rfenghou__yujig"] = "王者荣耀",
  ["~rfenghou__yujig"] = "",
}

local chugeqi = fk.CreateTriggerSkill{
  name = "rfenghou__chugeqi",
  events = {fk.AfterDying},
  frequency = Skill.Limited,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or target.dead then return false end
    return target:isWounded() and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__chugeqi-invoke:"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
    local full = false
    for _, cur in ipairs(room:getAlivePlayers()) do
      while not cur.dead and not target.dead and target:isWounded() do
        local cardNames = {"peach"}
        local prompt = "#AskForPeaches:" .. target.id .. "::" .. tostring(target.maxHp - target.hp)
        if cur == target then
          table.insert(cardNames, "analeptic")
          prompt = "#AskForPeachesSelf:::" .. tostring(target.maxHp - target.hp)
        end

        cardNames = table.filter(cardNames, function (cardName)
          -- FIXME: 应该印一个“任何情况都适合”的牌，或者说根本不该有这个过滤
          local cardCloned = Fk:cloneCard(cardName)
          return not (cur:prohibitUse(cardCloned) or cur:isProhibited(target, cardCloned))
        end)
        if #cardNames == 0 then return end

        local peach_use = room:askForUseCard(
          cur,
          "peach",
          table.concat(cardNames, ","),
          prompt,
          true,
          {analepticRecover = true, must_targets = { target.id }, fix_targets = { target.id }}
        )
        if not peach_use then break end
        peach_use.tos = { {target.id} }
        if peach_use.card.trueName == "analeptic" then
          peach_use.extra_data = peach_use.extra_data or {}
          peach_use.extra_data.analepticRecover = true
        end
        room:useCard(peach_use)
        if not target:isWounded() then
          full = true
        end
        for _, p in ipairs({player, target, cur}) do
          if not p.dead then
            p:drawCards(1, self.name)
          end
        end
      end
    end
    if full then
      RUtil.resetSkill(player, self)
    end
  end,
}
yujig:addSkill(chugeqi)

Fk:loadTranslationTable{
  ["rfenghou__chugeqi"] = "楚歌起",
  [":rfenghou__chugeqi"] = "限定技，一名角色脱离濒死后，你可以令其再进行一轮求【桃】询问，有角色响应时，你，目标，使用者各摸一张牌，其因此回复所有体力后，重置此技能。",
  ["#rfenghou__chugeqi-invoke"] = "楚歌起：你可以询问所有角色对 %src 使用【桃】",

  ["$rfenghou__chugeqi1"] = "",
  ["$rfenghou__chugeqi2"] = "",
}


local gaixiabie = fk.CreateTriggerSkill{
  name = "rfenghou__gaixiabie",
  events = {fk.CardUsing},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or target.dead then return false end
    local logic = player.room.logic
    local use_event = logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use_event == nil then return false end
    local last -- 上一名使用者的id
    logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
      local use = e.data[1]
      if e.id < use_event.id then
        last = use.from
        return true
      end
    end, 1)
    if not last or last == data.from or (last ~= player.id and target ~= player) then return false end
    -- 双向检查
    local fix = target:getMark("@@rfenghou__liandui_fix")
    if fix ~= 0 and fix ~= last then return false end
    fix = player.room:getPlayerById(last):getMark("@@rfenghou__liandui_fix")
    if fix ~= 0 and fix ~= target.id then return false end
    self.cost_data = last
    return true
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, nil, "#rfenghou__liandui-invoke:"..player.id .. ":" .. self.cost_data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    player:broadcastSkillInvoke("rfenghou__liandui")
    local toId = self.cost_data
    room:notifySkillInvoked(player, self.name, player == target and "support" or "drawcard", {toId})
    room:doIndicate(target.id, {toId})
    local to = room:getPlayerById(toId)
    if target:getMark("@@rfenghou__liandui_fix") == 0 then
      room:addTableMarkIfNeed(target, "rfenghou__liandui_tar", toId)
      if table.contains(to:getTableMark("rfenghou__liandui_tar"), target.id) then
        room:setPlayerMark(to, "@@rfenghou__liandui_fix", target.id)
        room:setPlayerMark(target, "@@rfenghou__liandui_fix", to.id)
      end
    end
    to:drawCards(2, self.name)
  end,
  on_acquire = function (self, player, is_start)
    player.room:handleAddLoseSkills(player, "rfenghou__liandui", self.name) -- 幽默虚假技能
  end,
  on_lose = function (self, player, is_death)
    local room = player.room
    local fix = player:getMark("@@rfenghou__liandui_fix")
    if fix == 0 then return end
    fix = room:getPlayerById(fix)
    room:setPlayerMark(player, "@@rfenghou__liandui_fix", 0)
    room:setPlayerMark(fix, "@@rfenghou__liandui_fix", 0)
  end,
}

local gaixiabie2 = fk.CreateTriggerSkill{
  name = "#rfenghou__gaixiabie_delay",
  events = {fk.EnterDying},
  main_skill = gaixiabie,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(gaixiabie) and player == target then
      local fix = player:getMark("@@rfenghou__liandui_fix")
      if fix == 0 then return false end
      fix = player.room:getPlayerById(fix)
      return fix:isAlive()
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(player:getMark("@@rfenghou__liandui_fix"))
    room:doIndicate(player.id, {to.id})
    -- 失去本技能，令对方获得战绝
    room:handleAddLoseSkills(player, "-rfenghou__gaixiabie")
    room:handleAddLoseSkills(to, "steam__zhanjue")
  end,
}
gaixiabie:addRelatedSkill(gaixiabie2)

yujig:addSkill(gaixiabie)

local liandui = fk.CreateTriggerSkill{
  name = "rfenghou__liandui",
}
yujig:addRelatedSkill(liandui)

--[[
local zhanjue = fk.CreateViewAsSkill{
  name = "rfenghou__zhanjue",
  anim_type = "offensive",
  prompt = "#rfenghou__zhanjue",
  card_filter = function(self, to_select, selected)
    return false
  end,
  view_as = function(self, cards)
    local card = Fk:cloneCard("duel")
    card:addSubcards(Self:getCardIds(Player.Hand))
    return card
  end,
  after_use = function(self, player, use)
    local room = player.room
    if not player.dead then
      player:drawCards(1, self.name)
      room:addPlayerMark(player, "zhanjue-phase", 1)
    end
    if use.damageDealt then
      for _, p in ipairs(room.alive_players) do
        if use.damageDealt[p.id] then
          p:drawCards(1, self.name)
          if p == player then
            room:addPlayerMark(player, "zhanjue-phase", 1)
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("zhanjue-phase") < 2 and not player:isKongcheng()
  end
}
yujig:addRelatedSkill(zhanjue)
--]]

Fk:loadTranslationTable{
  ["rfenghou__gaixiabie"] = "垓下别",
  [":rfenghou__gaixiabie"] = "你视为拥有“联对”，其他角色与你均因此令对方摸过牌后，令此技能仅对其生效，你进入濒死后，将此技能交给其并将“”中的内容替换为“战绝”。",
  ["@@rfenghou__liandui_fix"] = "联对",
  ["#rfenghou__gaixiabie_delay"] = "垓下别",

  ["rfenghou__liandui"] = "联对",
  [":rfenghou__liandui"] = "当你使用一张牌时，若上一张牌的使用者不为你，你可以令其摸两张牌；其他角色使用一张牌时，若上一张牌的使用者为你，其可以令你摸两张牌。",
  ["#rfenghou__liandui-invoke"] = "联对：你可以发动 %src 的“联对”，令 %dest 摸两张牌",

  ["rfenghou__zhanjue"] = "战绝",
  [":rfenghou__zhanjue"] = "出牌阶段，你可以将所有手牌当【决斗】使用，然后你和受伤的角色各摸一张牌。若你此法摸过两张或更多的牌，则本阶段〖战绝〗失效。",
  ["#rfenghou__zhanjue"] = "战绝：你可以将所有手牌当【决斗】使用，然后你和受伤的角色各摸一张牌",

  ["$rfenghou__liandui1"] = "以句相联，抒离散之苦。",
  ["$rfenghou__liandui2"] = "以诗相对，颂哀怨之情。",
}

-- 南宫杯
local liuhong = General:new(extension, "rfenghou__liuhong", "han", 4)
Fk:loadTranslationTable{
  ["rfenghou__liuhong"] = "刘宏",
  ["#rfenghou__liuhong"] = "四林偃望",
  ["designer:rfenghou__liuhong"] = "zhengqunhen",
  ["cv:rfenghou__liuhong"] = "",
  ["illustrator:rfenghou__liuhong"] = "四百",
}

---@param player ServerPlayer
---@param num integer
local doLizheng = function (player, num)
  local skill_name = "rfenghou__lizheng"
  player:drawCards(num, skill_name)
  if player.dead then return end
  local room = player.room
  if num == 1 then
    if room:askForUseActiveSkill(player, "zhiheng", "#rfenghou__lizheng-zhiheng") then
      player:broadcastSkillInvoke("zhiheng")
    end
  elseif num == 2 then
    room:addPlayerMark(player, MarkEnum.SlashResidue.."-turn")
  elseif num == 3 then
    local judge = {
      who = player,
      reason = "lightning",
      pattern = ".|2~9|spade",
    }
    room:judge(judge)
    if not player.dead and
      judge.card.suit == Card.Spade and judge.card.number > 1 and judge.card.number < 10 then
      room:damage{
        to = player,
        damage = 3,
        damageType = fk.ThunderDamage,
        skillName = skill_name,
      }
    end
  end
end

local yujue = fk.CreateTriggerSkill{
  name = "rfenghou__yujue",
  events = {fk.TurnStart},
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player ~= target and not target:isNude() then
      return not table.contains(player:getTableMark("rfenghou__yujue_tar-round"), target.id)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(target, 1, 3, true, self.name, true, nil, "#rfenghou__yujue-give:"..player.id)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, "rfenghou__yujue_tar-round", target.id)
    room:doIndicate(target.id, {player.id})
    local cards = self.cost_data
    room:obtainCard(player, cards, true, fk.ReasonGive, target.id, self.name)
    if target.dead then return end
    if player:hasSkill(self, true) and room:askForSkillInvoke(player, self.name, nil, "#rfenghou__yujue-refuse:"..target.id) then
      room:handleAddLoseSkills(player, "-"..self.name)
      return false
    end
    room:setPlayerMark(target, "rfenghou__yujue_num-turn", #cards)
  end,
}

local yujue2 = fk.CreateTriggerSkill{
  name = "#rfenghou__yujue_delay",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark("rfenghou__yujue_num-turn") ~= 0 and player == target and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local num = player:getMark("rfenghou__yujue_num-turn")
    return player.room:askForSkillInvoke(player, "", nil, "#rfenghou__lizheng-choice"..num)
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke("rfenghou__lizheng")
    player.room:notifySkillInvoked(player, "rfenghou__lizheng", "drawcard")
    local num = player:getMark("rfenghou__yujue_num-turn")
    doLizheng(player, num)
  end,
}
yujue:addRelatedSkill(yujue2)

liuhong:addSkill(yujue)

Fk:loadTranslationTable{
  ["rfenghou__yujue"] = "鬻爵",
  [":rfenghou__yujue"] = "每轮每角色限一次，其他角色的回合开始时，其可正面朝上交给你一至三张牌，（你可失去此技能并拒绝之）你令其本回合获得仅有项号与其本次给出牌数相同且无前置限制的“理政”。",
  ["#rfenghou__yujue-give"] = "鬻爵：你可以交给 %src 1-3张牌，本回合获得给牌张数对应项的“理政”",
  ["#rfenghou__yujue-refuse"] = "点击“确定”：失去“鬻爵”以拒绝 %src 发动“理政”",
}

local taozong = fk.CreateViewAsSkill{
  name = "rfenghou__taozong",
  pattern = ".|.|.|.|.|basic",
  prompt = "#rfenghou__taozong",
  attached_skill_name = "rfenghou__taozong&",
  interaction = function (self, player)
    local choices = U.getViewAsCardNames(player, self.name, U.getAllCardNames("b"))
    if #choices > 0 then
      return U.CardNameBox { choices = choices }
    end
  end,
  card_filter = function (self, to_select, selected, player)
    return #selected < 2 and table.contains(player.player_cards[Player.Hand], to_select)
  end,
  view_as = function (self, cards, player)
    if not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = self.name
    if #cards == 2 then
      c:addSubcards(cards)
    elseif #cards == 0 and #player:getCardIds("e") > 0 then
      c:addSubcards(player.player_cards[Player.Equip])
    else
      return nil
    end
    return c
  end,
  enabled_at_play = Util.TrueFunc,
  enabled_at_response = function (self, player, response)
    if player.phase ~= Player.NotActive and (#player:getCardIds("e") > 0 or #player:getCardIds("h") > 1) then
      return #U.getViewAsCardNames(player, self.name, U.getAllCardNames("b")) > 0
    end
  end,
}

local taozong_other = fk.CreateViewAsSkill{
  name = "rfenghou__taozong&",
  pattern = ".|.|.|.|.|basic",
  prompt = "#rfenghou__taozong",
  interaction = function (self, player)
    local choices = U.getViewAsCardNames(player, taozong.name, U.getAllCardNames("b"))
    if #choices > 0 then
      return U.CardNameBox { choices = choices }
    end
  end,
  card_filter = function (self, to_select, selected, player)
    return #selected < 2 and table.contains(player.player_cards[Player.Hand], to_select)
  end,
  view_as = function (self, cards, player)
    if not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = taozong.name
    if #cards == 2 then
      c:addSubcards(cards)
    elseif #cards == 0 and #player:getCardIds("e") > 0 then
      c:addSubcards(player.player_cards[Player.Equip])
    else
      return nil
    end
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    local current = room.current
    if current and current:hasSkill(taozong, true) and
    room:askForSkillInvoke(current, taozong.name, nil, "#rfenghou__taozong-refuse:"..player.id.."::"..use.card.name) then
      room:handleAddLoseSkills(current, "-"..taozong.name)
      return self.name
    end
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function (self, player, response)
    local current = Fk:currentRoom().current
    if current and current:hasSkill(taozong) and (#player:getCardIds("e") > 0 or #player:getCardIds("h") > 1) then
      return #U.getViewAsCardNames(player, self.name, U.getAllCardNames("b")) > 0
    end
  end,
}
Fk:addSkill(taozong_other)

liuhong:addSkill(taozong)

Fk:loadTranslationTable{
  ["rfenghou__taozong"] = "滔纵",
  [":rfenghou__taozong"] = "你回合内，所有角色可将其所有装备区的牌或两张手牌当作一张基本牌使用或打出（你可失去此技能并取消之）。",
  ["#rfenghou__taozong"] = "滔纵：将装备区所有牌或两张手牌当作一张基本牌使用或打出",
  ["rfenghou__taozong&"] = "滔纵",
  [":rfenghou__taozong&"] = "在刘宏回合内，你可将所有装备区的牌或两张手牌当作一张基本牌使用或打出（其可失去“滔纵”并取消之）。",
  ["#rfenghou__taozong-refuse"] = "可点“确认”：失去“滔纵”以取消 %src 发动“滔纵”转化【%arg】",
}


local lizheng = fk.CreateTriggerSkill{
  name = "rfenghou__lizheng",
  events = {fk.EventPhaseStart},
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player == target and player.phase == Player.Start then
      if not player:hasSkill("rfenghou__yujue") and not player:hasSkill("rfenghou__taozong") then
        return true
      end
      local roles = {}
      for _, p in ipairs(player.room.alive_players) do
        table.insertIfNeed(roles, p.role)
      end
      return #roles == 2
    end
  end,
  on_cost = function (self, event, target, player, data)
    local _, dat = player.room:askForUseActiveSkill(player, "rfenghou__lizheng_active", "#rfenghou__lizheng-choice")
    if dat then
      self.cost_data = dat.interaction
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local num = self.cost_data
    doLizheng(player, num)
  end,
}
liuhong:addSkill(lizheng)

local lizheng_active = fk.CreateActiveSkill{
  name = "rfenghou__lizheng_active",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  interaction = function(self)
    return UI.Spin { from = 1, to = 3 }
  end,
  prompt = function (self, selected_cards, selected_targets)
    local num = self.interaction.data or 1
    return "#rfenghou__lizheng-choice"..num
  end,
}
Fk:addSkill(lizheng_active)

Fk:loadTranslationTable{
  ["rfenghou__lizheng"] = "理政",
  [":rfenghou__lizheng"] = "场上仅剩两种身份，或已失去“鬻爵”、“滔纵”时，你才能发动此技能。准备阶段，你可以摸一至三张牌并执行下列中序号与摸牌数相同的一项：①发动“制衡”②本回合使用【杀】上限+1③进行一次【闪电】判定。",
  ["rfenghou__lizheng_active"] = "理政",
  ["#rfenghou__lizheng-choice1"] = "理政：摸1张牌，并发动“制衡”",
  ["#rfenghou__lizheng-choice2"] = "理政：摸2张牌，【杀】次数+1",
  ["#rfenghou__lizheng-choice3"] = "理政：摸3张牌，进行【闪电】判定",
  ["#rfenghou__lizheng-zhiheng"] = "理政：请发动“制衡”",
  ["#rfenghou__lizheng-choice"] = "理政：你可以摸1-3张牌，然后执行对应内容",
}


local xiaoyan = General:new(extension, "rfenghouif__xiaoyan", "liang", 4)

---@param i integer @ 连招条件对应的数字 1:基本牌 2:单体牌 3:伤害牌 4:【杀】5:非基本牌 6:非单体牌 7:非伤害牌 8:非【杀】
---@param card Card @ 使用的牌
---@param hasPlayerTarget integer @ 有无目标牌对应的数字，需在传到此函数前先判断 1:有目标牌 2:无目标牌
--匹配蔽月展示的牌与所有连招条件的符合情况
local function xiaoyanBiyueCheck(i, card, hasPlayerTarget)
  if i == 1 then
    return card.type == Card.TypeBasic
  elseif i == 2 then
    return hasPlayerTarget == 1 and not card.multiple_targets
  elseif i == 3 then
    return card.is_damage_card
  elseif i == 4 then
    return card.trueName == "slash"
  elseif i == 5 then
    return card.type ~= Card.TypeBasic
  elseif i == 6 then
    return card.multiple_targets or hasPlayerTarget == 2
  elseif i == 7 then
    return not card.is_damage_card
  elseif i == 8 then
    return card.trueName ~= "slash"
  end
end

---@param i integer @ 连招条件对应的数字 1:基本牌 2:单体牌 3:伤害牌 4:【杀】5:非基本牌 6:非单体牌 7:非伤害牌 8:非【杀】
local function xiaoyanBiyueNumber(i) --用以直接修改非XX条件的函数
  if i == 1 then
    return 5
  elseif i == 2 then
    return 6
  elseif i == 3 then
    return 7
  elseif i == 4 then
    return 8
  elseif i == 5 then
    return 1
  elseif i == 6 then
    return 2
  elseif i == 7 then
    return 3
  elseif i == 8 then
    return 4
  end
end

local rfenghou__xiaoyan__biyue = fk.CreateTriggerSkill{
  name = "rfenghou__xiaoyan__biyue",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and
    data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[self.name]
  end,
  on_cost = function (self, event, target, player, data)
  local banner = player.room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
  local invoke = player.room:askForSkillInvoke(player, self.name, nil)
    if invoke then
      for loop = 0, 10086, 1 do 
        local name = "rfenghou__xiaoyan__biyue"..loop
        if banner and banner[name] and banner[name][3] == player.id then
          banner[name][2] = 1
          player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
        end
      end
      return true
    else
      for loop = 0, 10086, 1 do 
        local name = "rfenghou__xiaoyan__biyue"..loop
        if banner and banner[name] and banner[name][3] == player.id then
          banner[name][2] = 1
          player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getCardIds("h"), function (cid)  
      return (Fk:getCardById(cid).type == Card.TypeBasic or Fk:getCardById(cid):isCommonTrick()) and #Fk:getCardById(cid):getAvailableTargets(player, {bypass_times = true}) > 0
    end)
    if #ids == 0 then return false end
    local cards = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|hand|.|.|"..table.concat(ids,","), "#rfenghou__xiaoyan__biyue-show")
    if #cards > 0 then
    local show = cards[1]
    player:showCards({show})
    local banner = room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
    if banner == {} or banner == nil then return false end
    local x = 1 --哈哈，故技重施，代码一半都是循环体搜索条件去了
    local choices = {}
    for loop = 0, 10086, 1 do
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if xiaoyanBiyueCheck(banner[name][1], Fk:getCardById(cards[1]), 1) == true then --前面不给展示没有目标的牌，头疼死了还要判断目标类型
          if banner[name][2] == 2 then
            table.insert(choices, "第"..x.."个："..Fk:translate("<font color=\'green'>biyue"..banner[name][1].."</font>"))
          else
            table.insert(choices, "第"..x.."个："..Fk:translate("biyue"..banner[name][1]))
          end
        end
        x = x + 1
      end
    end
      if #choices > 0 then
      local choice = room:askForChoice(player, choices, self.name, "#rfenghou__xiaoyan__biyue-choice")
      local change = room:askForChoice(player, {"reverse_combo", "slash"}, self.name, "#rfenghou__xiaoyan__biyue-change:::"..Fk:translate(choice))
        if #choice > 0 and #change > 0 then
        local y = 1
        for loop = 0, 10086, 1 do 
          local name = "rfenghou__xiaoyan__biyue"..loop
          if banner and banner[name] and banner[name][3] == player.id then
            if banner[name][2] == 2 then
                if choice == "第"..y.."个："..Fk:translate("<font color=\'green'>biyue"..banner[name][1].."</font>") then
                  if change == "reverse_combo" then
                  banner[name][1] = xiaoyanBiyueNumber(banner[name][1])
                  room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
                  elseif change == "slash" then
                  banner[name][1] = 4
                  room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
                  end
                  break
                end
            else
              if choice == "第"..y.."个："..Fk:translate("biyue"..banner[name][1]) then
                if change == "reverse_combo" then
                  banner[name][1] = xiaoyanBiyueNumber(banner[name][1])
                  room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
                  elseif change == "slash" then
                  banner[name][1] = 4
                  room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
                  end
                break
              end
            end
            y = y + 1
          end
        end
      end
    end
    local card = Fk:cloneCard(Fk:getCardById(show).name)
    card.skillName = self.name
    local canUse = false
    local extra_data = { bypass_times = true }
    if player:canUse(card, extra_data) and not player:prohibitUse(card) then canUse = true end
    local dat
    if canUse then
      room:setPlayerMark(player, "rfenghou__xiaoyan__biyue", card.name)
      _, dat = player.room:askForUseViewAsSkill(player, "rfenghou__xiaoyan__biyue_viewas", "#rfenghou__xiaoyan__biyue-use:::"..card.name, true, extra_data)
    end
    if dat then
      room:useCard{
        from = player.id,
        tos = table.map(dat.targets, function(p) return {p} end),
        card = card,
        extraUse = true
      }
    end
    end
  end,

  dynamic_desc = function(self, player)
    local banner = Fk:currentRoom():getBanner("rfenghou__xiaoyan__biyue_combos")
    if banner == nil then return self.name end
    --[].连招条件序号 1.连招条件（1~8） 2.是否已满足（1/2) 3.连招技的拥有者（返回ID）
    local info = "连招技（"
    for loop = 0, 10086, 1 do 
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if info == "连招技（" then
          if banner[name][2] == 2 then
          info = info.."<font color=\'green'>"..Fk:translate("biyue"..banner[name][1]).."</font>"
          elseif banner[name][2] == 1 then
          info = info..Fk:translate("biyue"..banner[name][1])
          end
        else
          if banner[name][2] == 2 then
          info = info.."+<font color=\'green'>"..Fk:translate("biyue"..banner[name][1]).."</font>"
        elseif banner[name][2] == 1 then
          info = info.."+"..Fk:translate("biyue"..banner[name][1])
          end
        end
      end
    end
    return info.."），结算后你可以展示一张基本牌或普通锦囊牌并视为使用之。若此牌满足任意连招条件，将满足条件前加一个“非”或改为【杀】。"..
      "<br><font color=\'red'>连招进度请查看对局中的动态描述，</font><font color=\'green'>绿色</font><font color=\'red'>为已完成！</font>"
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true) and data.card
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local banner = room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
    if banner == {} or banner == nil then return false end
    local combodone = true
    local hasPlayerTarget = 1
    if type(data.tos) ~= "table" then --多传一个用来判断无目标牌
      hasPlayerTarget = 2
    end
    for loop = 0, 10086, 1 do
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id and banner[name][2] == 1 then --优先匹配第一个未完成的
        if xiaoyanBiyueCheck(banner[name][1], data.card, hasPlayerTarget) == true then
          banner[name][2] = 2
          player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
        elseif xiaoyanBiyueCheck(banner[name][1], data.card, hasPlayerTarget) == false then
          for i = 0, 10086, 1 do
            local iname = "rfenghou__xiaoyan__biyue"..i
            if banner and banner[iname] and banner[iname][3] == player.id then
              banner[iname][2] = 1
              player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
            end
          end
        end
        break
      end
    end
    for loop = 0, 10086, 1 do --判断完当前使用牌的进度符合条件以后再逐个寻找连招技进度
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if banner[name][2] == 1 then
          combodone = false
          break
        end
      end
    end
    if combodone then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[self.name] = true
    return
    end
  end,

  on_acquire = function (self, player, is_start)
    --[].连招条件序号 1.连招条件（1~8） 2.是否已满足（1/2) 3.连招技的拥有者（返回ID）
    local banner = player.room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
    local name = "rfenghou__xiaoyan__biyue"
    local x = 1
      for i = 0, 10086, 1 do
        if banner["rfenghou__xiaoyan__biyue"..tostring(i)] == nil then
          name = "rfenghou__xiaoyan__biyue"..tostring(i)
          banner[name] = {
            x, -- 1:基本牌 2:单体牌 3:伤害牌 4:【杀】5:非基本牌 6:非单体牌 7:非伤害牌 8:非【杀】
            1, -- 1:未满足 2:已满足
            player.id,
          }
          player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
          x = x + 1
          if x > 3 then break end
        end
      end
    player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
    player.room:setPlayerMark(player, "@rfenghou__xiaoyan__biyue", 3)
  end,

  on_lose = function (self, player, is_death)
    for loop = 0, 10086, 1 do 
      local name = "rfenghou__xiaoyan__biyue"..loop
      local infos = player.room:getBanner("rfenghou__xiaoyan__biyue_combos")
      if infos and infos[name] and infos[name][3] == player.id then
        infos[name] = nil
        player.room:setBanner("rfenghou__xiaoyan__biyue_combos", infos)
      end
    end
    player.room:setPlayerMark(player, "@rfenghou__xiaoyan__biyue", 0)
  end,
}
local rfenghou__xiaoyan__biyue_viewas = fk.CreateViewAsSkill{
  name = "rfenghou__xiaoyan__biyue_viewas",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local card = Fk:cloneCard(Self:getMark("rfenghou__xiaoyan__biyue"))
    card.skillName = "rfenghou__xiaoyan__biyue"
    return card
  end,
}
Fk:addSkill(rfenghou__xiaoyan__biyue_viewas)
xiaoyan:addSkill(rfenghou__xiaoyan__biyue)

Fk:loadTranslationTable{ --1到4是四个肯定的连招条件，5到8是四个否定的连招条件
  ["@rfenghou__xiaoyan__biyue"] = "蔽月",
  ["rfenghou__xiaoyan__biyue_viewas"] = "蔽月",
  ["#rfenghou__xiaoyan__biyue-use"] = "蔽月：可以视为使用展示牌%arg，请指定此牌目标！",
  ["biyue1"] = "基本牌",
  ["biyue2"] = "单体牌",
  ["biyue3"] = "伤害牌",
  ["biyue4"] = "【杀】",
  ["biyue5"] = "非基本牌",
  ["biyue6"] = "非单体牌",
  ["biyue7"] = "非伤害牌",
  ["biyue8"] = "非【杀】",
  ["<font color=\'green'>biyue1</font>"] = "<font color=\'green'>基本牌</font>",
  ["<font color=\'green'>biyue2</font>"] = "<font color=\'green'>单体牌</font>",
  ["<font color=\'green'>biyue3</font>"] = "<font color=\'green'>伤害牌</font>",
  ["<font color=\'green'>biyue4</font>"] = "<font color=\'green'>【杀】</font>",
  ["<font color=\'green'>biyue5</font>"] = "<font color=\'green'>非基本牌</font>",
  ["<font color=\'green'>biyue6</font>"] = "<font color=\'green'>非单体牌</font>",
  ["<font color=\'green'>biyue7</font>"] = "<font color=\'green'>非伤害牌</font>",
  ["<font color=\'green'>biyue8</font>"] = "<font color=\'green'>非【杀】</font>",
}
local rfenghou__xiaoyan__fanyin = fk.CreateTriggerSkill{
  name = "rfenghou__xiaoyan__fanyin",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:hasSkill("rfenghou__xiaoyan__biyue", true) and player.phase == Player.Start
    and player:getMark("@rfenghou__xiaoyan__biyue") >= 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local banner = room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
    if banner == nil then return false end
    local choices = {}
    local x = 1
    --[].连招条件序号 1.连招条件（1~8） 2.是否已满足（1/2) 3.连招技的拥有者（返回ID）
    for loop = 0, 10086, 1 do 
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if banner[name][2] == 2 then
          table.insert(choices, "第"..x.."个："..Fk:translate("<font color=\'green'>biyue"..banner[name][1].."</font>"))
        else
          table.insert(choices, "第"..x.."个："..Fk:translate("biyue"..banner[name][1]))
        end
        x = x + 1
      end
    end
    local choice = room:askForChoices(player, choices, 2, 2, self.name, "#rfenghou__xiaoyan__fanyin-choice", false)
    if #choice == 2 then
    local y = 1
    local cannotBeSlash = false
    local notSlash = false
    for loop = 0, 10086, 1 do 
      local name = "rfenghou__xiaoyan__biyue"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if banner[name][2] == 2 then
          if table.contains(choice, "第"..y.."个："..Fk:translate("<font color=\'green'>biyue"..banner[name][1].."</font>")) then
            if banner[name][1] == 8 then
              notSlash = true
            end
            if banner[name][1] > 4 and banner[name][1] <= 8 then
              cannotBeSlash = true
            end
            banner[name] = nil
            room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
            room:removePlayerMark(player, "@rfenghou__xiaoyan__biyue", 1)
          end
        else
          if table.contains(choice, "第"..y.."个："..Fk:translate("biyue"..banner[name][1])) then
            if banner[name][1] == 8 then
              notSlash = true
            end
            if banner[name][1] > 4 and banner[name][1] <= 8 then
              cannotBeSlash = true
            end
            banner[name] = nil
            room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
            room:removePlayerMark(player, "@rfenghou__xiaoyan__biyue", 1)
          end
        end
        y = y + 1
      end
    end
    local to = room:askForChoosePlayers(player, table.map(room:getAllPlayers(), Util.IdMapper), 1, 1,
    "#rfenghou__xiaoyan__fanyin-damage", self.name, false)
      if #to > 0 then
      room:damage{
        from = player,
        to = room:getPlayerById(to[1]),
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
      end
      if not room:getPlayerById(to[1]).dead then
        if cannotBeSlash then
          room:setPlayerMark(room:getPlayerById(to[1]), "@@rfenghou__xiaoyan__biyue_noslash", 1)
        end
        if notSlash then
          room:setPlayerMark(room:getPlayerById(to[1]), "@@rfenghou__xiaoyan__biyue_cruse", 1)
        end
      end
    end
  end,

  refresh_events = {fk.TurnStart, fk.BeforeHpChanged},
  can_refresh = function (self, event, target, player, data)
    return event == fk.TurnStart or (event == fk.BeforeHpChanged and target:getMark("@@rfenghou__xiaoyan__biyue_cruse") > 0
    and data.num < 0 and data.num + player.hp < 0 and not (data.extra_data and data.extra_data.rfenghou__xiaoyan__fanyin == true))
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      for _, p in ipairs(room:getAllPlayers()) do
        if p:getMark("@@rfenghou__xiaoyan__biyue_noslash") ~= 0 then
          room:setPlayerMark(p, "@@rfenghou__xiaoyan__biyue_noslash", 0)
          room:setPlayerMark(p, "@@rfenghou__xiaoyan__biyue_notslash-turn", 1)
        end
      end
    elseif event == fk.BeforeHpChanged then
      data.extra_data = data.extra_data or {}
      data.extra_data.rfenghou__xiaoyan__fanyin = true
      data.num = (data.num or 0) - 1
    end
  end,
}
local rfenghou__xiaoyan__fanyin_prohibit = fk.CreateProhibitSkill{
  name = "#rfenghou__xiaoyan__fanyin_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@@rfenghou__xiaoyan__biyue_notslash-turn") > 0 then
      return card.trueName == "slash"
    end
  end,
}
rfenghou__xiaoyan__fanyin:addRelatedSkill(rfenghou__xiaoyan__fanyin_prohibit)
xiaoyan:addSkill(rfenghou__xiaoyan__fanyin)

local rfenghou__xiaoyan__wuxiang = fk.CreateTriggerSkill{
  name = "rfenghou__xiaoyan__wuxiang",
  frequency = Skill.Compulsory,
  events = {fk.Damaged, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or not player:hasSkill("rfenghou__xiaoyan__biyue", true) then return false end
    return target == player
  end,
  on_cost = function(self, event, target, player, data)
    local choices = {"addcombo"}
    local x = player:getMark("@rfenghou__xiaoyan__biyue")
    if player:getHandcardNum() ~= x then
      table.insert(choices, 2, "adjusttocombo")
    end
    local choice = player.room:askForChoice(player, choices, self.name, "#rfenghou__xiaoyan__wuxiang")
    if choice ~= nil then
      self.cost_data = choice 
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local y = player:getMark("@rfenghou__xiaoyan__biyue")
    local banner = room:getBanner("rfenghou__xiaoyan__biyue_combos") or {}
    local name = "rfenghou__xiaoyan__biyue"
    if self.cost_data == "adjusttocombo" then
      if y > player:getHandcardNum() then
        player:drawCards(y - player:getHandcardNum(), self.name)
      elseif y < player:getHandcardNum() then
        room:askForDiscard(player, player:getHandcardNum() - y, player:getHandcardNum() - y, false, self.name, false)
      end
    elseif self.cost_data == "addcombo" then
      local choices = {"biyue1","biyue2","biyue3"}
      local choice = room:askForChoice(player, choices, self.name, "#rfenghou__xiaoyan__wuxiang-choice")
      local number
      if choice == "biyue1" then
        number = 1
      elseif choice == "biyue2" then
        number = 2
      elseif choice == "biyue3" then
        number = 3
      end
      local z = 0
      for loop = 0, 10086, 1 do 
        local name = "rfenghou__xiaoyan__biyue"..loop
        if banner and banner[name] and banner[name][3] == player.id then
          z = loop
        end
      end
      for i = z, 10086, 1 do --强制从序号最大的banner之后开始插入
        if banner["rfenghou__xiaoyan__biyue"..tostring(i)] == nil then
          name = "rfenghou__xiaoyan__biyue"..tostring(i)
          banner[name] = {
            number, -- 1:基本牌 2:单体牌 3:伤害牌 4:【杀】5:非基本牌 6:非单体牌 7:非伤害牌 8:非【杀】
            1, -- 1:未满足 2:已满足
            player.id,
          }
          player.room:setBanner("rfenghou__xiaoyan__biyue_combos", banner)
          break
        end
      end
      player.room:addPlayerMark(player, "@rfenghou__xiaoyan__biyue", 1)
    end
  end,
}
xiaoyan:addSkill(rfenghou__xiaoyan__wuxiang)

Fk:loadTranslationTable{
  ["rfenghouif__xiaoyan"] = "萧衍",
  ["#rfenghouif__xiaoyan"] = "帝利什刹",
  ["designer:rfenghouif__xiaoyan"] = "屑",
  ["cv:rfenghouif__xiaoyan"] = "妙啊",
  ["illustrator:rfenghouif__xiaoyan"] = "萧炎",

  ["rfenghou__xiaoyan__biyue"] = "蔽月",
  [":rfenghou__xiaoyan__biyue"] = "连招技（基本牌+单体牌+伤害牌），每回合限一次，结算后你可以展示一张基本牌或普通锦囊牌并视为使用之。若此牌满足任意连招条件，将满足条件前加一个“非”或改为【杀】。"..
  "<br><font color=\'red'>连招进度请查看对局中的动态描述，</font><font color=\'green'>绿色</font><font color=\'red'>为已完成！</font>",
  ["rfenghou__xiaoyan__fanyin"] = "梵音",
  [":rfenghou__xiaoyan__fanyin"] = "准备阶段，你可失去“蔽月”中的两个连招条件，分配1点雷电伤害。若已选项中至少一个：不能为【杀】，受伤角色下回合无法使用【杀】；为“非【杀】”，受伤角色此后脱离濒死所需回复值+1。",
  ["rfenghou__xiaoyan__wuxiang"] = "无相",
  [":rfenghou__xiaoyan__wuxiang"] = "锁定技，你造成或受到伤害后，选择一项：将“蔽月”初始的一个连招条件添加为最后的连招条件；或将手牌数调整至X（X为“蔽月”连招条件数）。",

  ["reverse_combo"] = "反转",
  ["addcombo"] = "增加初始连招条件至末项",
  ["adjusttocombo"] = "调整手牌数至连招条件数",
  ["@@rfenghou__xiaoyan__biyue_noslash"] = "梵音 将不可杀",
  ["@@rfenghou__xiaoyan__biyue_notslash-turn"] = "梵音 不可用杀",
  ["@@rfenghou__xiaoyan__biyue_cruse"] = "梵音 增加求桃",
  ["#rfenghou__xiaoyan__biyue-show"] = "蔽月：请展示一张基本牌或普通锦囊牌，以视为使用之！",
  ["#rfenghou__xiaoyan__biyue-choice"] = "梵音：请选择一个符合展示牌的连招条件修改！",
  ["#rfenghou__xiaoyan__biyue-change"] = "蔽月：请将此前选择的连招条件%arg修改为“非此条件”或“【杀】”！",
  ["#rfenghou__xiaoyan__fanyin-choice"] = "梵音：请将一个“蔽月“的连招条件删去(绿色为已完成！)，然后分配1点雷电伤害！",
  ["#rfenghou__xiaoyan__fanyin-damage"] = "梵音：请分配1点雷电伤害！",
  ["#rfenghou__xiaoyan__wuxiang-choice"] = "无相：请将一个“蔽月“最初的连招条件置入连招末项！",
  ["#rfenghou__xiaoyan__wuxiang"] = "无相：是否将手牌数调整至“蔽月”条件数，或为“蔽月”添加一个初始条件？",

  ["$rfenghou__xiaoyan__biyue1"] = "一微尘里三千界，半刹那间八万春。",
  ["$rfenghou__xiaoyan__biyue2"] = "竹影扫阶尘不动，月照穿潭水无痕。",
  ["$rfenghou__xiaoyan__biyue3"] = "非月动，非云动，唯我心动。",
  ["$rfenghou__xiaoyan__fanyin1"] = "五蕴皆空，六尘不染，是谓和尚。",
  ["$rfenghou__xiaoyan__fanyin2"] = "百福庄严、千花自在，如地如月，胜出一切！",
  ["$rfenghou__xiaoyan__wuxiang1"] = "证实相、无人法，须臾灭却阿鼻业。",
  ["$rfenghou__xiaoyan__wuxiang2"] = "佛印戒珠，皆我心印；雾露云霞，本来一是。",
  ["~rfenghouif__xiaoyan"] = "世尊，以何缘故！世尊，何因缘故！",
}

local sunhao = General:new(extension, "rfenghou__sunhao", "wu", 4)
Fk:loadTranslationTable{
  ["rfenghou__sunhao"] = "孙皓",
  ["#rfenghou__sunhao"] = "",
  ["designer:rfenghou__sunhao"] = "屑",
  ["cv:rfenghou__sunhao"] = "",
  ["illustrator:rfenghou__sunhao"] = "yranT",

  ["rfenghou__zhanwang"] = "谵妄",
  [":rfenghou__zhanwang"] = "当你弃置所有手牌后，失去1点体力并从以下处各获得一张牌：①中央区；②牌堆顶；③场上；当你造成伤害后，可以将其中一项改为受伤角色的名字。（不可重复）",
  ["rfenghou__jinzun"] = "金樽",
  [":rfenghou__jinzun"] = "锁定技，你的体力值不提供手牌上限，改为提供额定摸牌数；你的武器牌不提供技能，改为获得一个“本局游戏限X次，你可以视为使用一张【酒】（X为此牌攻击范围）”的技能。",
  ["rfenghou__hunhun"] = "惛惛",
  [":rfenghou__hunhun"] = "主公技，锁定技，游戏开始时，“谵妄”后添加吴势力角色数个空白项；当所有项首次均为人名后，这些角色各减少1点体力上限，你回复等量点体力。",

  ["CenterArea"] = "中央区",
  ["DrawPileTop"] = "牌堆顶",
  ["CardInBoard"] = "场上",
  ["Blank"] = "空白",
  ["rfenghou__jinzunjiu"] = "金樽",
  [":rfenghou__jinzunjiu"] = "本局游戏限X次，你可以视为使用一张【酒】。",
  ["#rfenghou__zhanwang_getCenter"] = "谵妄：请获得中央区一张牌！",
  ["#rfenghou__zhanwang_getInBoard"] = "谵妄：请选择场上一张牌获得！(已按角色座次排序)",
  ["#rfenghou__zhanwang_getPlayer"] = "谵妄：请选择%dest区域内的一张牌获得！",
  ["#rfenghou__zhanwang-choice"] = "谵妄：请选择一个选项改为%dest的名字！",
}
local zhanwang = fk.CreateTriggerSkill{
  name = "rfenghou__zhanwang",
  events = {fk.AfterCardsMove, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.AfterCardsMove and player:isKongcheng() then
      for _, move in ipairs(data) do
        if move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            return info.fromArea == Card.PlayerHand
          end
        end
      end
    elseif event == fk.Damage then
      if target == player then
        local can = true
        for loop = 1, 30, 1 do
          if player:getMark("rfenghou__zhanwang_areatoplayer"..loop) == data.to.id then
            can = false
            break
          end
        end
      return can
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return true
    else
      return player.room:askForSkillInvoke(player, self.name, nil)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:loseHp(player, 1, self.name)
      if player.dead then return false end
      for loop = 1, 30, 1 do
        local mark = player:getMark("rfenghou__zhanwang_area"..loop)
        if mark ~= 0 and mark ~= "Blank" then
          if mark == "CenterArea" and player.room:getBanner("@$CenterArea") ~= nil and #player.room:getBanner("@$CenterArea") > 0 then
            local get = room:askForCardsChosen(player, player, 1, 1, {
              card_data = {
                { "CenterArea", room:getBanner("@$CenterArea") }
              }
            }, self.name, "#rfenghou__zhanwang_getCenter")
            if #get > 0 then
              room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
            end
          elseif mark == "DrawPileTop" then
            if #room.draw_pile > 0 then
              local cards = room:getNCards(1)
              if #cards > 0 then
                player.room:obtainCard(player, cards, false, fk.ReasonJustMove)
              end
            end
          elseif mark == "CardInBoard" then
            local markin = player:getTableMark("rfenghou__zhanwang")
            room:setPlayerMark(player, "rfenghou__zhanwang", 0) --每次发动先初始化代替技能流程结束以后的清理
            for _, p in ipairs(player.room:getAllPlayers()) do
              for _, id in ipairs(p:getCardIds("ej")) do
                table.insertIfNeed(markin, id)
              end
            end
            room:setPlayerMark(player, "rfenghou__zhanwang", #markin > 0 and markin or 0)
            if #markin > 0 then
              local get = room:askForCardsChosen(player, player, 1, 1, {
                card_data = {
                  {"rfenghou__zhanwang", player:getTableMark("rfenghou__zhanwang")}
                }
              }, self.name, "#rfenghou__zhanwang_getInBoard")
              if #get > 0 then
                room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
              end
            end
          else
            if not room:getPlayerById(player:getMark("rfenghou__zhanwang_areatoplayer"..loop)):isAllNude() then
              local get = room:askForCardsChosen(player, room:getPlayerById(player:getMark("rfenghou__zhanwang_areatoplayer"..loop)), 1, 1, "hej", 
              self.name, "#rfenghou__zhanwang_getPlayer::"..player:getMark("rfenghou__zhanwang_areatoplayer"..loop))
              if #get > 0 then
                room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player.id)
              end        
            end
          end
        end
      end
    elseif event == fk.Damage then
      local choices = {}
      for loop = 1, 30, 1 do
        local mark = player:getMark("rfenghou__zhanwang_area"..loop)
        if mark ~= 0 then
          table.insert(choices, "第"..loop.."个："..Fk:translate(mark))
        end
      end
      local choice = room:askForChoice(player, choices, self.name, "#rfenghou__zhanwang-choice::"..data.to.id)
      if #choice > 0 then
        for loop = 1, 30, 1 do
          local mark = player:getMark("rfenghou__zhanwang_area"..loop)
          if choice == "第"..loop.."个："..Fk:translate(mark) then
            player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..loop, data.to.general) --这个方便动态描述直接调用
            player.room:setPlayerMark(player, "rfenghou__zhanwang_areatoplayer"..loop, data.to.id)
          end
        end
      end
    end
  end,
  dynamic_desc = function(self, player)
    local info = ""
    for loop = 1, 30, 1 do
      local mark = player:getMark("rfenghou__zhanwang_area"..loop)
      if mark ~= 0 then
        if info == "" then
          info = loop.."."..Fk:translate(mark)..";"
        else
          info = info.." "..loop.."."..Fk:translate(mark)..";"
        end
      end
    end
    if info == "" then return self.name end
    return "当你弃置所有手牌后，失去1点体力并从以下处各获得一张牌："..info.." 当你造成伤害后，可以将其中一项改为受伤角色的名字（不可重复）。"
  end,

  refresh_events = {fk.AfterCardsMove},  --从安比这里扒了一个清理器，问就是获取场上牌的写法会受移动场上牌的影响，需要排除
  can_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.PlayerJudge then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerJudge then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.from and move.toArea ~= Card.PlayerEquip and move.toArea ~= Card.PlayerJudge then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerJudge then
            for _, p in ipairs(room:getAllPlayers()) do
              local mark = p:getTableMark("rfenghou__zhanwang")
              if #mark > 0 then
                table.removeOne(mark, info.cardId)
                room:setPlayerMark(p, "rfenghou__zhanwang", #mark > 0 and mark or 0)
              end
            end
          end
        end
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..1, "CenterArea")
    player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..2, "DrawPileTop")
    player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..3, "CardInBoard")
  end,

  on_lose = function (self, player, is_death)
    for loop = 1, 30, 1 do 
      player.room:setPlayerMark(player, "rfenghou__zhanwang_areatoplayer"..loop, 0)
      player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..loop, 0)
    end
  end,
}
sunhao:addSkill(zhanwang)
zhanwang.CenterArea = true

local jinzun = fk.CreateTriggerSkill{
  name = "rfenghou__jinzun",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.n = data.n + player.hp
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill("rfenghou__jinzun") then return false end
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if (move.to == player.id and move.toArea == Card.PlayerEquip)
        or (move.from == player.id and info.fromArea == Card.PlayerEquip) then
          return Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if move.to == player.id and move.toArea == Card.PlayerEquip and Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
          for _, skill in ipairs(player.player_skills) do
            if skill.attached_equip and Fk:cloneCard(skill.attached_equip).sub_type == Card.SubtypeWeapon then
              if Fk.skills[skill] and player:hasSkill(skill, true) then
                player.room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
              end
              if Fk.skills[skill.name] and player:hasSkill(skill.name, true) then
                player.room:handleAddLoseSkills(player, "-"..skill.name, nil, true, false)
              end
            end
          end
          for i = 0, 30, 1 do
            local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
            if not player:hasSkill(name, true) then
              player:setSkillUseHistory(name, 0, Player.HistoryGame)
              player.room:setPlayerMark(player, ""..name, Fk:getCardById(info.cardId).attack_range ~= nil and Fk:getCardById(info.cardId).attack_range or 1)
              player.room:setPlayerMark(player, ""..name.."record", Fk:getCardById(info.cardId).name) --记录一下卡牌名字，用来定位删除的技能
              player.room:handleAddLoseSkills(player, name, nil, true, false)
              break
            end
          end
        elseif move.from == player.id and info.fromArea == Card.PlayerEquip and Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
          for i = 0, 30, 1 do
            local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
            if player:hasSkill(name, true) and player:getMark(""..name.."record") == Fk:getCardById(info.cardId).name then
              player:setSkillUseHistory(name, 0, Player.HistoryGame)
              player.room:setPlayerMark(player, ""..name, 0)
              player.room:setPlayerMark(player, ""..name.."record", 0)
              player.room:handleAddLoseSkills(player, "-"..name, nil, true, false)
              break
            end
          end
        end
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    for _, skill in ipairs(player.player_skills) do
      if skill.attached_equip and Fk:cloneCard(skill.attached_equip).sub_type == Card.SubtypeWeapon then
        if Fk.skills[skill] and player:hasSkill(skill, true) then
        player.room:handleAddLoseSkills(player, "-"..skill, nil, true, false)
        end
        if Fk.skills[skill.name] and player:hasSkill(skill.name, true) then
          player.room:handleAddLoseSkills(player, "-"..skill.name, nil, true, false)
        end
      end
    end
    for _, e in ipairs(player.player_cards[Player.Equip]) do
      if Fk:getCardById(e).sub_type == Card.SubtypeWeapon then
        for i = 0, 30, 1 do
          local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
          if not player:hasSkill(name, true) then
            player:setSkillUseHistory(name, 0, Player.HistoryGame)
            player.room:setPlayerMark(player, ""..name, Fk:getCardById(e).attack_range ~= nil and Fk:getCardById(e).attack_range or 1)
            player.room:setPlayerMark(player, ""..name.."record", Fk:getCardById(e).name) --记录一下卡牌名字，用来定位删除的技能
            player.room:handleAddLoseSkills(player, name, nil, true, false)
            break
          end
        end 
      end
    end
  end,

  on_lose = function (self, player, is_death)
    for i = 0, 30, 1 do
      local name = i == 0 and "rfenghou__jinzunjiu" or "rfenghou"..i.."__jinzunjiu"
      if player:hasSkill(name, true) then
        player:setSkillUseHistory(name, 0, Player.HistoryGame)
        player.room:setPlayerMark(player, ""..name, 0)
        player.room:setPlayerMark(player, ""..name.."record", 0)
        player.room:handleAddLoseSkills(player, "-"..name, nil, true, false)
      end
    end
  end,
}
local jinzun_maxcards = fk.CreateMaxCardsSkill{
  name = "#rfenghou__jinzun_maxcards",
  correct_func = function(self, player)
    if player:hasSkill("rfenghou__jinzun") then
      return - player.hp
    end
  end
}
jinzun:addRelatedSkill(jinzun_maxcards)
sunhao:addSkill(jinzun)
for loop = 0, 30, 1 do 
  local jinzunjiu = fk.CreateViewAsSkill{
    name = loop == 0 and "rfenghou__jinzunjiu" or "rfenghou"..loop.."__jinzunjiu",
    anim_type = "offensive",
    pattern = "analeptic",
    card_filter = Util.FalseFunc,
    times = function (self)
      return Self:getMark(""..self.name)
    end,
    dynamic_desc = function(self, player)
      local mark = player:getMark(""..self.name) 
      local mark2 = player:getMark(""..self.name.."record") ~= nil and player:getMark(""..self.name.."record") or "不可用"
      return "本局游戏限"..mark.."次，你可以视为使用一张【酒】（来源：【"..Fk:translate(mark2).."】）。"
    end,
    view_as = function(self, cards)
      local c = Fk:cloneCard("analeptic")
      c.skillName = self.name
      return c
    end,
    before_use = function(self, player, use)
      local room = player.room 
      room:removePlayerMark(player, ""..self.name, 1)
    end,
    enabled_at_play = function(self, player)
      return player:getMark(""..self.name) > 0
    end,
    enabled_at_response = function(self, player, res)
      local to_use = Fk:cloneCard("analeptic")
      return not res and Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use)
      and player:getMark(""..self.name) > 0
    end,
  }
  if loop > 0 then
    Fk:addSkill(jinzunjiu)
  else
    sunhao:addRelatedSkill(jinzunjiu)
  end
  Fk:loadTranslationTable{
    ["rfenghou"..loop.."__jinzunjiu"] = "金樽",
    [":rfenghou"..loop.."__jinzunjiu"] = "本局游戏限X次，你可以视为使用一张【酒】。",
  }
end

local hunhun = fk.CreateTriggerSkill{
  name = "rfenghou__hunhun$",
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or not player:hasSkill("rfenghou__zhanwang") then return false end
    if event == fk.GameStart then
      return true
    elseif event == fk.AfterSkillEffect then
      local canuse = true
      for loop = 1, 30, 1 do
        local mark = player:getMark("rfenghou__zhanwang_area"..loop)
        if mark ~= 0 then
          if mark == "CenterArea" or mark == "DrawPileTop" or mark == "CardInBoard" or mark == "Blank" then
            canuse = false
          end
        end
      end
      return data.name == "rfenghou__zhanwang" and canuse and player:usedSkillTimes(self.name, Player.HistoryGame) <= 1
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.GameStart then
    local h = 0
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p.kingdom == "wu" then
        h = h + 1
      end
    end
    for loop = 1, 30, 1 do --空白项冗余只能给这么多了
      if player:getMark("rfenghou__zhanwang_area"..loop) == 0 then
        player.room:setPlayerMark(player, "rfenghou__zhanwang_area"..loop, "Blank")
        h = h - 1
        if h == 0 then break end
      end
    end
    elseif event == fk.AfterSkillEffect then
      player:setSkillUseHistory(self.name, 2, Player.HistoryGame) --中途获得主公技也可触发，在一次发动后均为人名的谵妄结算后触发，然后设置发动次数伪限定
      local list = {}
      for loop = 1, 30, 1 do
        local mark = player:getMark("rfenghou__zhanwang_area"..loop)
        if mark ~= 0 then
          if mark ~= "CenterArea" and mark ~= "DrawPileTop" and mark ~= "CardInBoard" and mark ~= "Blank" then
            if not player.room:getPlayerById(player:getMark("rfenghou__zhanwang_areatoplayer"..loop)).dead then
              table.insertIfNeed(list, player.room:getPlayerById(player:getMark("rfenghou__zhanwang_areatoplayer"..loop)))
            end
          end
        end
      end
      if #list > 0 then
        for _, p in ipairs(list) do
          if not p.dead then
            player.room:changeMaxHp(p, -1)
          end
        end
      end
      if not player.dead then
        player.room:recover({ who = player,  num = #list, skillName = self.name })
      end
    end
  end,
}

sunhao:addSkill(hunhun)

local nieyinniang = General:new(extension, "rfenghou__nieyinniang", "tang", 3, 3, General.Female)
Fk:loadTranslationTable{
  ["rfenghou__nieyinniang"] = "聂隐娘",
  ["#rfenghou__nieyinniang"] = "暮为行雨",
  ["designer:rfenghou__nieyinniang"] = "君腾天下",
  ["cv:rfenghou__nieyinniang"] = "邪恶母蟑螂",
  ["illustrator:rfenghou__nieyinniang"] = "英雄杀",

  ["rfenghou__feibi"] = "飞匕", --哈哈，武将牌上的技能还要不被隐匿重置掉，想开摆了
  [":rfenghou__feibi"] = "连招技（【杀】），你可于此牌结算后隐匿，若如此做，①跳过你本回合的弃牌阶段，②你使用的下一张牌结算后，将之类型加入连招；"..
  "若类型为装备牌，你直接登场并视为倒序使用其余连招条件，最后清除所有非【杀】条件，其中为类型的条件改为你从该类型牌中任意选择一张使用。"..
  "<br><font color=\'red'>连招进度请查看对局中的动态描述，</font><font color=\'green'>绿色</font><font color=\'red'>为已完成！</font>",
  ["rfenghou__qushou"] = "取首",
  [":rfenghou__qushou"] = "隐匿技，你登场时，可指定一名角色视为在你攻击范围内直到你的回合结束。",

  ["@rfenghou__feibi"] = "飞匕",
  ["#rfenghou__feibi_skip"] = "飞匕",
  ["@@rfenghou__feibi_add"] = "飞匕 添加条件",
  ["@@rfenghou__feibi_skip"] = "飞匕 跳弃",
  ["@rfenghou__qushou"] = "取首",
  ["#rfenghou__qushou-cost"] = "取首：是否选择一名角色，使你本回合的攻击范围包含其？",

  ["$rfenghou__feibi1"] = "飞剑蹑罡风，斫得云一朵。",
  ["$rfenghou__feibi2"] = "鱼肠数寸锋，座上流将血。",
  ["$rfenghou__qushou1"] = "刃未沾红，袖不染尘，借你头颅祭残月。",
  ["$rfenghou__qushou2"] = "听，玉冠犹问：“何时月过帘门？”",
  ["~rfenghou__nieyinniang"] = "无人为我磨心剑，观化亦难决疑情",
}

---@param i integer @ 连招条件对应的数字 1:基本牌 2:锦囊牌 3:装备牌 4:【杀】
---@param card Card @ 使用的牌
--匹配飞匕展示的牌与所有连招条件的符合情况
local function feibiCheck(i, card)
  if i == 1 then
    return card.type == Card.TypeBasic
  elseif i == 2 then
    return card.type == Card.TypeTrick
  elseif i == 3 then
    return card.type == Card.TypeEquip
  elseif i == 4 then
    return card.trueName == "slash"
  end
end

Fk:loadTranslationTable{
  ["feibi1"] = "基本牌",
  ["feibi2"] = "锦囊牌",
  ["feibi3"] = "装备牌",
  ["feibi4"] = "【杀】",
  ["<font color=\'green'>feibi1</font>"] = "<font color=\'green'>基本牌</font>",
  ["<font color=\'green'>feibi2</font>"] = "<font color=\'green'>锦囊牌</font>",
  ["<font color=\'green'>feibi3</font>"] = "<font color=\'green'>装备牌</font>",
  ["<font color=\'green'>feibi4</font>"] = "<font color=\'green'>【杀】</font>",
}

local feibi = fk.CreateTriggerSkill{
  name = "rfenghou__feibi",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
    data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[self.name]
  end,
  on_cost = function (self, event, target, player, data)
    local banner = player.room:getBanner("rfenghou__feibi_combos") or {}
    local invoke = player.room:askForSkillInvoke(player, self.name, nil)
      if invoke then
        for loop = 0, 10086, 1 do
          local name = "rfenghou__feibi"..loop
          if banner and banner[name] and banner[name][3] == player.id then
            banner[name][2] = 1
            player.room:setBanner("rfenghou__feibi_combos", banner)
          end
        end
        return true
      else
        for loop = 0, 10086, 1 do 
          local name = "rfenghou__feibi"..loop
          if banner and banner[name] and banner[name][3] == player.id then
            banner[name][2] = 1
            player.room:setBanner("rfenghou__feibi_combos", banner)
          end
        end
      end
    end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 then
    DIY.EnterHidden(player)
    end
    room:setPlayerMark(player, "@@rfenghou__feibi_add", 1)
    room:setPlayerMark(player, "@@rfenghou__feibi_skip", 1)
  end,

  dynamic_desc = function(self, player)
    local banner = Fk:currentRoom():getBanner("rfenghou__feibi_combos")
    if banner == nil then return self.name end
    --[].连招条件序号 1.连招条件（1~8） 2.是否已满足（1/2) 3.连招技的拥有者（返回ID）
    local info = "连招技（"
    for loop = 0, 10086, 1 do 
      local name = "rfenghou__feibi"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if info == "连招技（" then
          if banner[name][2] == 2 then
          info = info.."<font color=\'green'>"..Fk:translate("feibi"..banner[name][1]).."</font>"
          elseif banner[name][2] == 1 then
          info = info..Fk:translate("feibi"..banner[name][1])
          end
        else
          if banner[name][2] == 2 then
          info = info.."+<font color=\'green'>"..Fk:translate("feibi"..banner[name][1]).."</font>"
        elseif banner[name][2] == 1 then
          info = info.."+"..Fk:translate("feibi"..banner[name][1])
          end
        end
      end
    end
    return info.."），你可于此牌结算后隐匿，若如此做，①跳过你本回合的弃牌阶段，②你使用的下一张牌结算后，将之类型加入连招；"..
    "若类型为装备牌，你登场并视为倒序使用其余连招条件（为类型的条件改为你视为使用任意同类型牌），最后清除所有非【杀】条件。"..
    "<br><font color=\'red'>连招进度请查看对局中的动态描述，</font><font color=\'green'>绿色</font><font color=\'red'>为已完成！</font>"
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true) and data.card
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local banner = room:getBanner("rfenghou__feibi_combos") or {}
    if banner == {} or banner == nil then return false end
    local combodone = true
    for loop = 0, 10086, 1 do
      local name = "rfenghou__feibi"..loop
      if banner and banner[name] and banner[name][3] == player.id and banner[name][2] == 1 then --优先匹配第一个未完成的
        if feibiCheck(banner[name][1], data.card) == true then
          banner[name][2] = 2
          player.room:setBanner("rfenghou__feibi_combos", banner)
        elseif feibiCheck(banner[name][1], data.card) == false then
          for i = 0, 10086, 1 do
            local iname = "rfenghou__feibi"..i
            if banner and banner[iname] and banner[iname][3] == player.id then
              banner[iname][2] = 1
              player.room:setBanner("rfenghou__feibi_combos", banner)
            end
          end
        end
        break
      end
    end
    for loop = 0, 10086, 1 do --判断完当前使用牌的进度符合条件以后再逐个寻找连招技进度
      local name = "rfenghou__feibi"..loop
      if banner and banner[name] and banner[name][3] == player.id then
        if banner[name][2] == 1 then
          combodone = false
          break
        end
      end
    end
    if combodone then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[self.name] = true
    return
    end
  end,

  on_acquire = function (self, player, is_start)
    --[].连招条件序号 1.连招条件（1~4） 2.是否已满足（1/2) 3.连招技的拥有者（返回ID）
    local banner = player.room:getBanner("rfenghou__feibi_combos") or {}
    local add = true
    for loop = 1, 10086, 1 do
      local name = "rfenghou__feibi"..loop
      local infos = player.room:getBanner("rfenghou__feibi_combos")
      if infos and infos[name] and infos[name][3] == player.id then --如果已有聂隐娘的记录，则不触发后续添加连招
        add = false
        break
      end
    end
    local name
    if add then
      local x = 0
        for i = 1, 10086, 1 do
          if banner["rfenghou__feibi"..tostring(i)] == nil then
            name = "rfenghou__feibi"..tostring(i)
            banner[name] = {
              4, -- 1:基本牌 2:锦囊牌 3:装备牌 4:【杀】
              1, -- 1:未满足 2:已满足
              player.id,
            }
            player.room:setBanner("rfenghou__feibi_combos", banner)
            x = x + 1
            if x > 0 then break end
          end
        end
      player.room:setBanner("rfenghou__feibi_combos", banner)
      player.room:setPlayerMark(player, "@rfenghou__feibi", 1)
    end
  end,

  --说实话这个机制触发on_lose有点危险，要不哪个神人可以判断一下失去技能的原因
  --非隐匿状态下执行清理进度
  on_lose = function (self, player, is_death)
    if player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 then
    for loop = 1, 10086, 1 do 
      local name = "rfenghou__feibi"..loop
      local infos = player.room:getBanner("rfenghou__feibi_combos")
      if infos and infos[name] and infos[name][3] == player.id then
        infos[name] = nil
        player.room:setBanner("rfenghou__feibi_combos", infos)
      end
    end
    player.room:setPlayerMark(player, "@rfenghou__feibi", 0)
    end
  end,
}

local feibi_skip = fk.CreateTriggerSkill{ --耦合飞匕有关的所有后续
  name = "#rfenghou__feibi_skip",
  events = {fk.AfterCardUseDeclared},
  can_trigger = function (self, event, target, player, data)
    local add = false
    local infos = target.room:getBanner("rfenghou__feibi_combos")
    for loop = 1, 10086, 1 do
      local name = "rfenghou__feibi"..loop
      if infos and infos[name] and infos[name][3] == target.id then --已有记录才能添加连招
        add = true
        break
      end
    end
    return target == player and data.card and target:getMark("@@rfenghou__feibi_add") > 0 and add
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = target.room
    player:broadcastSkillInvoke("rfenghou__feibi")
    room:setPlayerMark(target, "@@rfenghou__feibi_add", 0)
    local banner = room:getBanner("rfenghou__feibi_combos") or {}
    if banner == {} or banner == nil then return false end
    local type
    if data.card and data.card.type == Card.TypeBasic then
      type = 1
    elseif data.card and data.card.type == Card.TypeTrick then
      type = 2
    elseif data.card and data.card.type == Card.TypeEquip then
      type = 3
    end
    local name
    local x = 0
    for i = 1, 10086, 1 do
      if banner["rfenghou__feibi"..tostring(i)] == nil then
        name = "rfenghou__feibi"..tostring(i)
        banner[name] = {
          type, -- 1:基本牌 2:锦囊牌 3:装备牌 4:【杀】
          1, -- 1:未满足 2:已满足
          target.id,
        }
        room:addPlayerMark(target, "@rfenghou__feibi", 1)
        room:setBanner("rfenghou__feibi_combos", banner)
        x = x + 1
        if x > 0 then break end
      end
    end
    if type == 3 then
      if not target.dead then
        local skill = Fk.skills["hidden_skill&"]
        if target:getMark("__hidden_general") ~= 0 or target:getMark("__hidden_deputy") ~= 0 then
          skill:trigger(fk.TurnStart, target, target, data)
        end
        for loop = 10086, 1, -1 do
          local name = "rfenghou__feibi"..loop
          if banner and banner[name] and banner[name][3] == target.id then
            banner[name][2] = 1 --先清除所有连招满足的进度
            room:setBanner("rfenghou__feibi_combos", banner)
          end
        end
        for loop = 10086, 1, -1 do
          if target.dead then break end
          local name = "rfenghou__feibi"..loop
          if banner and banner[name] and banner[name][3] == target.id then
            local cards
            if banner[name][1] == 1 then
              cards = U.getUniversalCards(room, "b", false)
            elseif banner[name][1] == 2 then
              cards = U.getUniversalCards(room, "t", false)
            elseif banner[name][1] == 4 then
              U.askForUseVirtualCard(room, target, "slash", nil, self.name, nil, false, true, false)
            end
            if cards ~= nil then
            local use = U.askForUseRealCard(room, target, cards, nil, self.name, nil,
              {expand_pile = cards, bypass_times = true, extraUse = true}, true, false)
            if use then
              use = {
                card = Fk:cloneCard(use.card.name),
                from = target.id,
                tos = use.tos,
              }
              use.card.skillName = self.name
              room:useCard(use)
            end
          end
            if banner[name][1] ~= 4 then
              banner[name] = nil
              room:removePlayerMark(target, "@rfenghou__feibi", 1)
              room:setBanner("rfenghou__feibi_combos", banner)
            end
          end
        end
      end
    end
  end,

  refresh_events = {fk.EventPhaseChanging},
  can_refresh = function(self, event, target, player, data)
    return player == target and data.to == Player.Discard and target:getMark("@@rfenghou__feibi_skip") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    target.room:setPlayerMark(target, "@@rfenghou__feibi_skip", 0)
    target:skip(data.to)
    return true
  end,
}

local qushou = fk.CreateTriggerSkill{
  name = "rfenghou__qushou",
  events = {"fk.GeneralAppeared"},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasShownSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    for _, p in ipairs(room:getAlivePlayers()) do
      table.insert(targets, p.id)
    end
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#rfenghou__qushou-cost", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data)
    player.room:setPlayerMark(to, "@rfenghou__qushou", player.general)
    player.room:setPlayerMark(to, "rfenghou__qushou", player.id)
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player == target
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room:getAllPlayers()) do
      if p:getMark("rfenghou__qushou") == player.id then
        player.room:setPlayerMark(p, "@rfenghou__qushou", 0)
        player.room:setPlayerMark(p, "rfenghou__qushou", 0)
      end
    end
  end,
}
local qushou_attackrange = fk.CreateAttackRangeSkill{
  name = "#rfenghou__qushou_attackrange",
  within_func = function (self, from, to)
    local mark = to:getMark("rfenghou__qushou")
    return mark ~= 0 and mark == from.id
  end,
}
feibi:addRelatedSkill(feibi_skip)
qushou:addRelatedSkill(qushou_attackrange)
nieyinniang:addSkill(feibi)
nieyinniang:addSkill(qushou)
qushou.isHiddenSkill = true

local wangmao = General:new(extension, "rfenghou__wangmao", "liang", 4)
Fk:loadTranslationTable{
  ["rfenghou__wangmao"] = "王茂",
  ["#rfenghou__wangmao"] = "契阔屯夷",
  ["designer:rfenghou__wangmao"] = "屑",
  ["cv:rfenghou__wangmao"] = "",
  ["illustrator:rfenghou__wangmao"] = "啪啪三国",

  ["rfenghou__jiechang"] = "接昌",
  [":rfenghou__jiechang"] = "一名角色弃牌阶段开始/结束时，若最后获得/失去牌的角色为你，你可以翻面并视为对至多两名角色使用【无中生有】/【杀】。",
  ["#rfenghou__jiechang_active1"] = "视为对至多两名角色使用【无中生有】!",
  ["#rfenghou__jiechang_active2"] = "视为对至多两名角色使用【杀】!",

  ["@@rfenghou__jiechang1"] = "接昌 无中",
  ["@@rfenghou__jiechang2"] = "接昌 杀",

  ["$rfenghou__jiechang1"] = "都下业重，大梦安觉，掷枕起、扫平天纲！",
  ["$rfenghou__jiechang2"] = "直驱秣陵，贼陈朱雀，引刃战、勋满宣阳！",
  ["~rfenghou__wangmao"] = "一生功业虽著，终老江州，犹为可憾...",
}
local jiechang = fk.CreateTriggerSkill{
  name = "rfenghou__jiechang",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase == Player.Discard and not target.dead then
      return (event == fk.EventPhaseStart and player:getMark("@@rfenghou__jiechang1") > 0) or
      (event == fk.EventPhaseEnd and player:getMark("@@rfenghou__jiechang2") > 0)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard("slash")
    local ex_nihilo = Fk:cloneCard("ex_nihilo")
    local targets1 = {}
    local targets2 = {}
    for _, p in ipairs(room:getOtherPlayers(player, false)) do
      if not player:isProhibited(p, slash) then
        table.insert(targets1, p.id)
      end
    end
    for _, p in ipairs(room:getAllPlayers()) do
      if not player:isProhibited(p, ex_nihilo) then
        table.insert(targets2, p.id)
      end
    end
    local propmt
    local targets
    if event == fk.EventPhaseStart then
      propmt = "#rfenghou__jiechang_active1"
      targets = targets2
    elseif event == fk.EventPhaseEnd then
      propmt = "#rfenghou__jiechang_active2"
      targets = targets1
    end
    if #targets == 0 then return end
    local tos = room:askForChoosePlayers(player, targets, 1, 2, propmt, self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local name
    if event == fk.EventPhaseStart then
      name = "ex_nihilo"
    elseif event == fk.EventPhaseEnd then
      name = "slash"
    end
    player:turnOver()
    if not player.dead then
      player.room:useVirtualCard(name, nil, player, table.map(self.cost_data, Util.Id2PlayerMapper), self.name, true)
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self, true) then
      for _, move in ipairs(data) do
        for _, info in ipairs(move.moveInfo) do
          return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip or move.toArea == Card.PlayerHand
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
          if move.from == player.id then
            player.room:setPlayerMark(player, "@@rfenghou__jiechang2", 1)
          else
            player.room:setPlayerMark(player, "@@rfenghou__jiechang2", 0)
          end
       elseif move.toArea == Card.PlayerHand then
          if move.to == player.id then
            player.room:setPlayerMark(player, "@@rfenghou__jiechang1", 1)
          else
            player.room:setPlayerMark(player, "@@rfenghou__jiechang1", 0)
          end
        end
      end
    end
  end,
}
wangmao:addSkill(jiechang)

--不是很想管什么同名替换，反正不按中文名检索同名武将基本就是烂完了，代码里面换前缀才是真的假把式还吃力不讨好...
local wangmaoo = General:new(extension, "rfenghou__wangmaoo", "liang", 4)
wangmaoo.hidden = true
Fk:loadTranslationTable{
  ["rfenghou__wangmaoo"] = "王茂",
  ["#rfenghou__wangmaoo"] = "金石台辅",
  ["designer:rfenghou__wangmaoo"] = "铝",
  ["cv:rfenghou__wangmaoo"] = "",
  ["illustrator:rfenghou__wangmaoo"] = "啪啪三国",

  ["rfenghou__zhenlan"] = "镇澜",
  [":rfenghou__zhenlan"] = "连招技（基本牌+普通锦囊牌，其他角色的连招进度），每种连招条件限一次，结算后，你可以发现符合或不符合本次连招条件中的一张牌并分配。",
  ["rfenghou__difeng"] = "砥锋",
  [":rfenghou__difeng"] = "每轮限一次，你可以将区域内一张牌面描述：含“杀”牌当【无懈可击】使用：不含“杀”当【闪】使用。结算前，你可与一名角色非锁定技失效至结算后。",
}
local zhenlan = fk.CreateTriggerSkill{
  name = "rfenghou__zhenlan",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local difeng = fk.CreateTriggerSkill{
  name = "rfenghou__difeng",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
wangmaoo:addSkill(zhenlan)
wangmaoo:addSkill(difeng)
wangmaoo:addSkill("zhongliu")

local dongfangbubai = General:new(extension, "rfenghou__dongfangbubai", "qun", 4, 4, General.Bigender)

Fk:loadTranslationTable{
  ["rfenghou__dongfangbubai"] = "东方不败",
  ["#rfenghou__dongfangbubai"] = "朱绫裁夜",
  ["designer:rfenghou__dongfangbubai"] = "老酒馆的猫",
  ["cv:rfenghou__dongfangbubai"] = "winsit",
  ["illustrator:rfenghou__dongfangbubai"] = "Sampan",
  ["~rfenghou__dongfangbubai"] = "倘若，我问心有愧呢？",
}

local kuihuacixue = fk.CreateTriggerSkill{
  name = "rfenghou__kuihuacixue",
  events = {fk.CardUseFinished},
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player ~= target or not player:hasSkill(self) then return false end
    local cid = data.card:getEffectiveId()
    if cid and player.room:getCardArea(cid) == Card.Processing then
      local tos = TargetGroup:getRealTargets(data.tos)
      if #tos == 1 then
        local to = player.room:getPlayerById(tos[1])
        if not to.dead and #to:getAvailableEquipSlots() > 0 then
          self.cost_data = {tos = tos}
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local toId = TargetGroup:getRealTargets(data.tos)[1]
    return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__kuihuacixue-invoke:"..toId)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(TargetGroup:getRealTargets(data.tos)[1])
    local cids = room:getSubcardsByRule(data.card, {Card.Processing})
    to:addToPile("rfenghou__sunflowerneedle",cids, true, self.name)
    local slots = to:getAvailableEquipSlots()
    if #slots > 0 then
      local slot = room:askForChoice(player, slots, self.name)
      room:abortPlayerArea(to, slot)
    end
    if not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
dongfangbubai:addSkill(kuihuacixue)
Fk:loadTranslationTable{
  ["rfenghou__kuihuacixue"] = "葵花刺穴",
  [":rfenghou__kuihuacixue"] = "你使用基本牌或普通锦囊牌结算后，你可以将之置于唯一目标的武将牌上，然后废除其一个装备栏并摸一张牌。",
  ["#rfenghou__kuihuacixue-invoke"] = "葵花刺穴：你可以将此牌置于 %src 脸上，废除其一个装备栏并摸一张牌。",
  ["rfenghou__sunflowerneedle"] = "针",

  ["$rfenghou__kuihuacixue1"] = "人间有情尽白发，天地无意了沧桑",
  ["$rfenghou__kuihuacixue2"] = "天予大任，赐我神功，日出东方，唯我不败！",
}

local xiuhuaduoming = fk.CreateTriggerSkill{
  name = "rfenghou__xiuhuaduoming",
  frequency = Skill.Limited,
  events = {fk.AreaAborted},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not target.dead then
      -- 逆天data值……
      return #target:getAvailableEquipSlots() == 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__xiuhuaduoming-invoke:"..target.id) then
      self.cost_data = {tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@rfenghou__xiuhuaduoming-phase", 1)
    local slots = table.simpleClone(target.equipSlots)
    room:resumePlayerArea(target, slots)
    local pile = table.simpleClone(target:getPile("rfenghou__sunflowerneedle"))
    while not target.dead do
      local ids = table.filter(pile, function(id)
        if not table.contains(target:getPile("rfenghou__sunflowerneedle"), id) then return false end
        local card = Fk:getCardById(id)
        return player:canUseTo(card, target, {bypass_distances = true, bypass_times = true})
      end)
      if #ids == 0 then break end
      local cid = ids[1]
      if not player.dead then
        cid = room:askForCardChosen(player, target, { card_data = { { "rfenghou__sunflowerneedle", ids } } }, self.name,
        "#rfenghou__xiuhuaduoming-use")
      end
      table.removeOne(pile, cid)
      room:useCard{
        from = player.id,
        tos = {{target.id}},
        card = Fk:getCardById(cid),
      }
    end
    room:setPlayerMark(target, "@@rfenghou__xiuhuaduoming-phase", 0)
  end,
}

local xiuhuaduoming_prohibit = fk.CreateProhibitSkill{
  name = "#rfenghou__xiuhuaduoming_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@@rfenghou__xiuhuaduoming-phase") ~= 0 and card
  end,
}
xiuhuaduoming:addRelatedSkill(xiuhuaduoming_prohibit)

dongfangbubai:addSkill(xiuhuaduoming)
Fk:loadTranslationTable{
  ["rfenghou__xiuhuaduoming"] = "绣花夺命",
  [":rfenghou__xiuhuaduoming"] = "限定技，一名角色装备栏均被废除后，你可以复原其装备栏并对其使用其武将牌上的所有“针”，其于结算期间不能使用牌。",
  ["@@rfenghou__xiuhuaduoming-phase"] = "被绣花夺命",
  ["#rfenghou__xiuhuaduoming-invoke"] = "绣花夺命：你可以复原 %src 所有装备栏，对其使用其的所有“针”",
  ["#rfenghou__xiuhuaduoming-use"] = "绣花夺命：选择一张“针”对其使用",

  ["$rfenghou__xiuhuaduoming1"] = "皇图霸业谈笑中，不胜人生一场醉",
  ["$rfenghou__xiuhuaduoming2"] = "风刀霜剑何相逼，只叹江湖几人回",
}

local huamulan = General:new(extension, "rfenghou__huamulan", "wei", 4, 4, General.Female)
Fk:loadTranslationTable{
  ["rfenghou__huamulan"] = "花木兰",
  ["#rfenghou__huamulan"] = "九霄神辉",
  ["designer:rfenghou__huamulan"] = "唐婉",
  ["cv:rfenghou__huamulan"] = "王者荣耀",
  ["illustrator:rfenghou__huamulan"] = "王者荣耀",
  ["~rfenghou__huamulan"] = "",
}
local tifu = fk.CreateTriggerSkill{
  name = "rfenghou__tifu",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local subtype_string_table = {
      [Card.SubtypeArmor] = "armor",
      [Card.SubtypeWeapon] = "weapon",
      [Card.SubtypeTreasure] = "treasure",
      [Card.SubtypeDelayedTrick] = "delayed_trick",
      [Card.SubtypeDefensiveRide] = "defensive_ride",
      [Card.SubtypeOffensiveRide] = "offensive_ride",
    }
    for _, slot in ipairs(player:getAvailableEquipSlots()) do
      if player.dead then return end
      local type = Util.convertSubtypeAndEquipSlot(slot)
      if #player:getEquipments(type) < #player:getAvailableEquipSlots(type) then
        local id = room:getCardsFromPileByRule(".|.|.|.|.|"..subtype_string_table[type], 1, "allPiles")[1]
        if id then
          room:useCard({
            from = player.id,
            tos = {{player.id}},
            card = Fk:getCardById(id),
          })
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove}, --后半段不会写成锁视，其实还是触发技好点
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerEquip then
          return true
        end
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if #player:getCardIds("e") > 0 and player.gender ~= General.Male then
      player.gender = General.Male
      player.room:broadcastProperty(player, "gender")
    elseif #player:getCardIds("e") == 0 and player.gender ~= General.Female then
      player.gender = General.Female
      player.room:broadcastProperty(player, "gender")
    end
  end,                        
}
huamulan:addSkill(tifu)
Fk:loadTranslationTable{
  ["rfenghou__tifu"] = "替父",
  [":rfenghou__tifu"] = "锁定技，游戏开始时，将每种副类型各一张装备置入你的装备栏。你的装备栏有牌时，你视为男性角色。",

  ["$rfenghou__tifu"] = "生而无畏，战至终章!",
}

local congjun = fk.CreateTriggerSkill{
  name = "rfenghou__congjun",
  switch_skill_name = "rfenghou__congjun",
  anim_type = "switch",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and
    data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[self.name] then
    if player:getSwitchSkillState(self.name) == fk.SwitchYang then
      return table.find(player.room.alive_players, function(p)
        for _, id in ipairs(player.room:getOtherPlayers(p)) do return p:canMoveCardsInBoardTo(id) end end)
      elseif player:getSwitchSkillState(self.name) == fk.SwitchYin then
        return not player:isNude()
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
  if ((player:getSwitchSkillState(self.name) == fk.SwitchYang and not table.find(player.room.alive_players, function(p) 
    for _, id in ipairs(player.room:getOtherPlayers(p)) do return p:canMoveCardsInBoardTo(id) end end)) or
    player:getSwitchSkillState(self.name) == fk.SwitchYin and player:isNude()) then
    player.room:setPlayerMark(player, "@rfenghou__congjun", 0)
    return false
  else
    if player:getSwitchSkillState(self.name) == fk.SwitchYang then
    local invoke = player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__congjun-invoke")
    if invoke then
      return true
    else
      player.room:setPlayerMark(player, "@rfenghou__congjun", 0)
      return false
    end
  elseif player:getSwitchSkillState(self.name) == fk.SwitchYin then
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "rfenghou__congjun-ask", true)
    if #card > 0 then
      if table.contains(player:getCardIds("e"), card) and #player:getCardIds("e") == 1 then
        player.room:throwCard(card, self.name, player, player)
        self.cost_data = 0
        return true
      else
        player.room:throwCard(card, self.name, player, player)
        return true
      end
    else
      player.room:setPlayerMark(player, "@rfenghou__congjun", 0)
      return false
    end
    end
  end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@rfenghou__congjun", 0)
    local yes = false
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      local targets = room:askForChooseToMoveCardInBoard(player, "#rfenghou__congjun-move", self.name, false)
      if #targets ~= 0 then
        local result = room:askForMoveCardInBoard(player, room:getPlayerById(targets[1]), room:getPlayerById(targets[2]), self.name)
        if result and result.from == player.id and #player:getCardIds("e") == 0 then
          yes = true
        end
        if result and not room:getPlayerById(result.to).dead and Fk:getCardById(result.card:getEffectiveId()).type == Card.TypeEquip then
          room:recover({
            who = room:getPlayerById(result.to),
            num = 1,
            recoverBy = player,
            skillName = self.name,
          })
        end
      end
    elseif player:getSwitchSkillState(self.name, true) == fk.SwitchYin then
      if self.cost_data == 0 then
        yes = true
      end
      data.extra_data = data.extra_data or {}
      data.extra_data.rfenghou__congjun = data.extra_data.rfenghou__congjun or {}
      data.extra_data.rfenghou__congjun = player.id
    end
    if yes then
      room:setPlayerMark(player, "@@rfenghou__congjun_all", 1)
    end
  end,

  refresh_events = {fk.CardUsing}, --不太清楚能不能在一般连招技声明使用的时机获取到目标，反正我先用耀嘉音的写法了，有更好的写法请务必告诉YD谢谢喵(ノ^o^)ノ
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true) and data.card
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    local mark = player:getTableMark("@rfenghou__congjun")
    local clear = true
    if #mark == 0 and type(data.tos) == "table" then
      for _, p in ipairs(targets) do
        if (room:getPlayerById(p).gender == General.Male or player:getMark("@@rfenghou__congjun_all") > 0) and clear then
        room:addTableMark(player, "@rfenghou__congjun", "√")
        clear = false
        break
        end
      end
  elseif #mark == 1 and data.card.trueName == "slash" then
      room:addTableMark(player, "@rfenghou__congjun", "√")
      clear = false
    end
    if clear then
      room:setPlayerMark(player, "@rfenghou__congjun", 0)
    end
    if #player:getTableMark("@rfenghou__congjun") == 2 then
        data.extra_data = data.extra_data or {}
        data.extra_data.combo_skill = data.extra_data.combo_skill or {}
        data.extra_data.combo_skill[self.name] = true
    return
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@rfenghou__congjun", 0)
  end,
}
local congjun_delay = fk.CreateTriggerSkill {
  name = "#rfenghou__congjun_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player.dead or data.card == nil or target ~= player then return false end
    return data.extra_data and data.extra_data.rfenghou__congjun and data.extra_data.rfenghou__congjun == player.id
    and table.find(player.room.alive_players, function(p) return table.contains(TargetGroup:getRealTargets(data.tos), p.id)  end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.extra_data and data.extra_data.rfenghou__congjun then
      local cards = {}
      for _, id in ipairs(U.getUniversalCards(room, "t")) do
        if Fk:getCardById(id).is_damage_card then
          table.insertIfNeed(cards, id)
        end
      end
      if #cards == 0 then return false end
      local use2 = U.askForUseRealCard(room, target, cards, nil, self.name, nil,
      {expand_pile = cards, bypass_times = true, extraUse = true, exclusive_targets = {table.unpack(TargetGroup:getRealTargets(data.tos))},}, true, false)
      if use2 then
        if #use2.tos == 0 then
          if use2.card.multiple_targets then
            use2.tos = {}
            for _, p in ipairs(TargetGroup:getRealTargets(data.tos)) do
              if not player:isProhibited(room:getPlayerById(p), use2.card) then
                if use2.card.skill:modTargetFilter(p, {}, player, card, false) then
                  table.insert(use2.tos, {p})
                end
              end
            end
          end
        end
      use2.card.skillName = self.name
      room:useCard(use2)
      end  
    end
  end,
}
congjun:addRelatedSkill(congjun_delay)
huamulan:addSkill(congjun)
Fk:loadTranslationTable{
  ["rfenghou__congjun"] = "从军",
  [":rfenghou__congjun"] = "转换技，连招技（使用牌指定男性角色+【杀】）阳：移动场上一张牌，令获得牌的角色回复1点体力。阴：弃置一张装备牌，此【杀】结"..
  "算后视为对目标使用一张伤害锦囊牌，若你因此失去了装备区最后一张牌，修改连招条件①为“任意性别角色”。",

  ["$rfenghou__congjun1"] = "以我长剑，荡尽九野!",
  ["$rfenghou__congjun2"] = "北望雄关万里，壮哉浩荡长风!",

  ["@rfenghou__congjun"] = "从军",
  ["#rfenghou__congjun_delay"] = "从军",
  ["@@rfenghou__congjun_all"] = "从军 均可",
  ["#rfenghou__congjun-invoke"] = "从军：（阳）是否移动场上一张牌，令获得牌的角色回复1点体力？",
  ["#rfenghou__congjun-move"] = "从军：请移动场上一张牌！因此获得装备牌的角色回复体力！",
  ["rfenghou__congjun-ask"] = "从军：（阴）弃置一张装备牌，以在此【杀】结算后视为对目标使用一张伤害锦囊牌？",
}

local huanxiang = fk.CreateTriggerSkill{
  name = "rfenghou__huanxiang",
  frequency = Skill.Wake,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player:usedSkillTimes(self.name, Player.HistoryGame) > 0 then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  can_wake = function (self, event, target, player, data)
    return #player:getCardIds("e") == 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(player, "efengqi__xiaoji")
  end,
}
huamulan:addSkill(huanxiang)
huamulan:addRelatedSkill("efengqi__xiaoji")
Fk:loadTranslationTable{
  ["rfenghou__huanxiang"] = "还乡",
  [":rfenghou__huanxiang"] = "觉醒技，你失去装备区最后一件装备时，减少1点体力上限获得“枭姬”。",

  ["$rfenghou__huanxiang"] = "止戈为武，四海承平。神辉所至，福幼生人!",
  ["$efengqi__xiaoji_rfenghou__huamulan1"] = "执长缨，死生同，征罢黄尘话封侯！",
  ["$efengqi__xiaoji_rfenghou__huamulan2"] = "麒麟踏祥云，人间百难消！",
}

local dengsui = General:new(extension, "rfenghou__dengsui", "han", 3, 3, General.Female)

Fk:loadTranslationTable{
  ["rfenghou__dengsui"] = "邓绥",
  ["#rfenghou__dengsui"] = " ",
  ["designer:rfenghou__dengsui"] = "折翼",
  ["cv:rfenghou__dengsui"] = "",
  ["illustrator:rfenghou__dengsui"] = "叁乔居",
}
local hebian = fk.CreateViewAsSkill{
  name = "rfenghou__hebian",
  switch_skill_name = "rfenghou__hebian",
  anim_type = "switch",
  pattern = "slash,peach",
  handly_pile = true,
  prompt = function (self)
    return "#rfenghou__hebian-"..Self:getSwitchSkillState(self.name, false, true)
  end,
  card_filter = function(self, to_select, selected, player)
    local n = player:getSwitchSkillState(self.name) == fk.SwitchYang and 1 or 2
    return #selected < n
  end,
  view_as = function(self, cards, player)
    local yang = player:getSwitchSkillState(self.name) == fk.SwitchYang
    if #cards ~= (yang and 1 or 2) then return nil end
    local c = Fk:cloneCard(yang and "peach" or "slash")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  after_use = function (self, player, use)
    local room = player.room
    local tos = table.map(TargetGroup:getRealTargets(use.tos), Util.Id2PlayerMapper)---@type ServerPlayer[]
    if use.card.trueName == "slash" then
      for _, to in ipairs(tos) do
        if not to.dead and not player.dead and #player:getCardIds("he") > 1 then
          if room:askForSkillInvoke(to, self.name, nil, "#rfenghou__hebian-askslash:"..player.id) then
            room:doIndicate(to.id, {player.id})
            local _, dat = room:askForUseViewAsSkill(player, "rfenghou__hebian_slash", "#rfenghou__hebian-slash",
            false, {bypass_times = true})
            if not dat then
              local cards = table.random(player:getCardIds("he"), 2)
              local card = Fk.skills["rfenghou__hebian_slash"]:viewAs(cards)
              if card and not player:prohibitUse(card) then
                local tars = U.getDefaultTargets(player, card, true)
                if #tars > 0 then
                  dat = {targets = tars, cards = cards}
                end
              end
            end
            if dat then
              local card = Fk.skills["rfenghou__hebian_slash"]:viewAs(dat.cards)
              room:useCard{
                from = player.id,
                tos = table.map(dat.targets, function(p) return {p} end),
                card = card,
                extraUse = true,
              }
            end
          end
        end
      end
    elseif use.card.trueName == "peach" then
      for _, to in ipairs(tos) do
        if not to.dead and to:isWounded() then
          local _, dat = room:askForUseViewAsSkill(to, "rfenghou__hebian_peach", "#rfenghou__hebian-peach", true)
          if dat then
            local card = Fk.skills["rfenghou__hebian_peach"]:viewAs(dat.cards)
            room:useCard{
              from = to.id,
              tos = table.map(dat.targets, function(p) return {p} end),
              card = card,
              extraUse = true,
            }
          end
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    if not response then
      local yang = player:getSwitchSkillState(self.name) == fk.SwitchYang
      local name = yang and "peach" or "slash"
      return Exppattern:Parse(Fk.currentResponsePattern):matchExp(name)
      and not player:prohibitUse(Fk:cloneCard(name))
    end
  end,
}
dengsui:addSkill(hebian)
local hebian_peach = fk.CreateViewAsSkill{
  name = "rfenghou__hebian_peach",
  handly_pile = true,
  card_filter = function(self, to_select, selected, player)
    return #selected < 1
  end,
  view_as = function(self, cards, player)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("peach")
    c.skillName = "rfenghou__hebian"
    c:addSubcards(cards)
    return c
  end,
}
Fk:addSkill(hebian_peach)
local hebian_slash = fk.CreateViewAsSkill{
  name = "rfenghou__hebian_slash",
  handly_pile = true,
  card_filter = function(self, to_select, selected, player)
    return #selected < 2
  end,
  view_as = function(self, cards, player)
    if #cards ~= 2 then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = "rfenghou__hebian"
    c:addSubcards(cards)
    return c
  end,
}
Fk:addSkill(hebian_slash)
Fk:loadTranslationTable{
  ["rfenghou__hebian"] = "阖变",
  [":rfenghou__hebian"] = "转换技，①你可以将一张牌当【桃】使用，然后目标也可如此做。②你可以将两张牌当【杀】使用，然后目标可令你再如此做。",
  ["#rfenghou__hebian-yin"] = "将两张牌当【杀】使用，目标可令你再如此做",
  ["#rfenghou__hebian-yang"] = "将一张牌当【桃】使用，然后目标也可如此做",
  ["rfenghou__hebian_peach"] = "阖变[桃]",
  ["rfenghou__hebian_slash"] = "阖变[杀]",
  ["#rfenghou__hebian-peach"] = "阖变：你可以将一张牌当【桃】使用",
  ["#rfenghou__hebian-slash"] = "阖变：你须将两张牌当【杀】使用！",
  ["#rfenghou__hebian-askslash"] = "阖变：你可以令 %src 须将两张牌当【杀】使用",
}

local getMiguiChoices = function (player)
  local used = player:getTableMark("rfenghou__migui_used")
  local color = #used > 3
  local choices = color and  {"red", "black"} or {"log_spade", "log_heart", "log_diamond", "log_club"}
  if color and player:hasSkill("rfenghou__shengtong") then
    table.insert(choices, "blue")
  end
  return table.filter(choices, function(c) return not table.contains(used, c) end)
end

---@param player ServerPlayer
local function updataMiguiMark(player)
  local room = player.room
  local suits, colors = {}, {}
  for _, p in ipairs(room.alive_players) do
    for _, v in ipairs(p:getTableMark("rfenghou__migui_record")) do
      if v[1] == player.id then
        local choice = v[2]
        if choice:startsWith("log_") then
          table.insert(suits, choice)
        else
          table.insert(colors, choice)
        end
      end
    end
  end
  room:setPlayerMark(player, "@rfenghou__migui_suit", #suits > 0 and suits or 0)
  local map = {["red"] = '<font color="#CC3131">红</font>', ["nocolor"] = '<font color="grey">无</font>', ["black"] = "黑"}
  room:setPlayerMark(player, "@rfenghou__migui_color", #colors > 0 and table.map(colors, function(c) return map[c] or c end) or 0)
end

local migui = fk.CreateActiveSkill{
  name = "rfenghou__migui",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  prompt = function (self)
    local choice = self.interaction.data
    if choice then
      return "#rfenghou__migui:::"..choice
    end
    return " "
  end,
  interaction = function(self, player)
    return UI.ComboBox { choices = getMiguiChoices(player) }
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  can_use = function(self, player)
    return #getMiguiChoices(player) > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local choice = self.interaction.data
    room:addTableMark(player, "rfenghou__migui_used", choice)
    room:addTableMark(player, "rfenghou__migui_record", {to.id, choice})
    updataMiguiMark(to)
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "rfenghou__migui_used", 0)
    local record = player:getMark("rfenghou__migui_record")
    if #record == 0 then return end
    local tos = {}
    for i = #record, 1, -1 do
      local v = record[i]
      table.insertIfNeed(tos, v[1])
    end
    if #tos == 0 then return end
    player.room:setPlayerMark(player, "rfenghou__migui_record", 0)
    for _, pid in ipairs(tos) do
      updataMiguiMark(player.room:getPlayerById(pid))
    end
  end,

  dynamic_desc = function (self, player, lang)
    if #player:getTableMark("rfenghou__migui_used") > 3 then
      return "rfenghou__migui_dyn"
    end
    return self.name
  end,
}

local function canTransferTarget(data, to)
  if data.card.skill:getMinTargetNum() > 1 then return false end
  local current_targets = TargetGroup:getRealTargets(data.tos)
  local from = Fk:currentRoom():getPlayerById(data.from)
  if not table.contains(current_targets, to.id) and not from:isProhibited(to, data.card) then
    if data.card.skill.trueName == "peach_skill" then ---傻逼桃
      return to:isWounded()
    else
      return data.card.skill:modTargetFilter(to.id, {}, from, data.card, false)
    end
  end
  return false
end

local migui_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__migui_delay",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    if target == player and not player.dead and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
      local color, suit = data.card:getColorString(), data.card:getSuitString(true)
      local record = player:getMark("rfenghou__migui_record")
      if record == 0 then return false end
      local toId, icon
      for _, v in ipairs(record) do
        if v[2] == color or v[2] == suit then
          toId = v[1]
          icon = v[2]
          break
        end
      end
      if toId then
        local to = player.room:getPlayerById(toId)
        if not to.dead and canTransferTarget(data, to) then
          self.cost_data = {toId, icon}
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, "rfenghou__migui", nil, "#rfenghou__migui-extra:"..
    (self.cost_data[1]).."::"..data.card:toLogString())
  end,
  on_use = function (self, event, target, player, data)
    local toId, icon = table.unpack(self.cost_data)
    player.room:doIndicate(player.id, {toId})
    table.insert(data.tos, {toId})
  end,

  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    return player:getMark("rfenghou__migui_record") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    local tos = {}
    local record = player:getMark("rfenghou__migui_record")
    if #record == 0 then return end
    for i = #record, 1, -1 do
      local v = record[i]
      if v[2]:startsWith("log_") then
        table.insertIfNeed(tos, v[1])
        table.remove(record, i)
      end
    end
    if #tos == 0 then return end
    player.room:setPlayerMark(player, "rfenghou__migui_record", #record > 0 and record or 0)
    for _, pid in ipairs(tos) do
      updataMiguiMark(player.room:getPlayerById(pid))
    end
  end,
}
migui:addRelatedSkill(migui_delay)
dengsui:addSkill(migui)
Fk:loadTranslationTable{
  ["rfenghou__migui"] = "觅轨",
  [":rfenghou__migui"] = "每种花色限一次，出牌阶段，你可为之指定一名角色，本回合你使用此花色的基本牌或普通锦囊牌可额外指定其为目标。每种花色均指定后，将花色改为颜色，本回合改为本局。",
  [":rfenghou__migui_dyn"] = "每种颜色限一次，出牌阶段，你可为之指定一名角色，本局你使用此颜色的基本牌或普通锦囊牌可额外指定其为目标。",
  ["#rfenghou__migui"] = "觅轨：指定一名角色，你使用【%arg】牌可额外指定其为目标",
  ["@rfenghou__migui_suit"] = "觅轨",
  ["@rfenghou__migui_color"] = "觅轨",
  ["#rfenghou__migui_delay"] = "觅轨",
  ["#rfenghou__migui-extra"] = "觅轨：你可以将 %src 额外指定为 %arg 的目标",

  ["$rfenghou__migui1"] = "",
  ["$rfenghou__migui2"] = "",
}

local shengtong = fk.CreateTriggerSkill{
  name = "rfenghou__shengtong$",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
dengsui:addSkill(shengtong)
Fk:loadTranslationTable{
  ["rfenghou__shengtong"] = "圣同",
  [":rfenghou__shengtong"] = "主公技，锁定技，修改后“觅轨”中，无色也视为一种颜色。",
}


local Bathory = General:new(extension, "rfenghou__Bathory", "west", 3, 6, General.Female)
Bathory.hidden = true
Fk:loadTranslationTable{
  ["rfenghou__Bathory"] = "血色玛丽",
  ["#rfenghou__Bathory"] = "狂厄蔷薇",
  ["designer:rfenghou__Bathory"] = "yyuaN",
  ["cv:rfenghou__Bathory"] = "",
  ["illustrator:rfenghou__Bathory"] = "AI",

  ["rfenghou__xuecuchangsheng"] = "血簇长生",
  [":rfenghou__xuecuchangsheng"] = "你造成或受到伤害时，可以横置受伤角色并加1点体力上限。你使用摸牌阶段外获得的牌造成伤害后，回复1点体力。",
  ["rfenghou__diaozhuoguimu"] = "凋灼瑰幕",
  [":rfenghou__diaozhuoguimu"] = "游戏开始或回合结束时，你可以扣减体力上限至体力值，每扣减1点，你便摸一张牌并隐匿（可叠加）。你于回合外登场后，直至你的回合开始，你于每回合结束时受到1点火焰伤害。",
}
local xuecuchangsheng = fk.CreateTriggerSkill{
  name = "rfenghou__xuecuchangsheng",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local diaozhuoguimu = fk.CreateTriggerSkill{
  name = "rfenghou__diaozhuoguimu",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
Bathory:addSkill(xuecuchangsheng)
Bathory:addSkill(diaozhuoguimu)

local qinghegongzhu = General:new(extension, "rfenghou__qinghegongzhu", "wei", 3, 3, General.Female)
qinghegongzhu.hidden = true
Fk:loadTranslationTable{
  ["rfenghou__qinghegongzhu"] = "清河公主",
  ["#rfenghou__qinghegongzhu"] = "荷怜清盈",
  ["designer:rfenghou__qinghegongzhu"] = "ab",
  ["cv:rfenghou__qinghegongzhu"] = "winsit",
  ["illustrator:rfenghou__qinghegongzhu"] = "depp",

  ["rfenghou__gouxian"] = "构陷",
  [":rfenghou__gouxian"] = "出牌阶段限一次，你可令一名角色检索至多三张黑色牌，然后展示其手牌，若其手牌中存在点数连续的黑色牌，令其失去2点体力。",
  ["rfenghou__gonglao"] = "共老",
  [":rfenghou__gonglao"] = "锁定技，其他角色于你出牌阶段展示手牌时，你也须展示手牌，若使展示牌中存在的点数连续牌数增多，你与其各摸两张牌。",

  ["$rfenghou__gouxian1"] = "楙苛待手足，致兄弟不睦，恐伤天家体面。",
  ["$rfenghou__gouxian2"] = "隶妾着翟衣僭仪制，伏惟陛下念及骨肉，免其死罪。",
  ["$rfenghou__gonglao1"] = "梦见邺城旧邸，君耕原上田，妾饲檐下蚕…",
  ["$rfenghou__gonglao2"] = "天家金枝，终不似荆钗布裙，为君怀丝缀旧衫。",
  ["~rfenghou__qinghegongzhu"] = "错将金枷玉锁系同心…恍然镜中成孤鸾…",
}
local gouxian = fk.CreateTriggerSkill{
  name = "rfenghou__gouxian",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local gonglao = fk.CreateTriggerSkill{
  name = "rfenghou__gonglao",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
qinghegongzhu:addSkill(gouxian)
qinghegongzhu:addSkill(gonglao)

local Sylvanas = General:new(extension, "rfenghou__Sylvanas", "west", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["rfenghou__Sylvanas"] = "希尔瓦娜斯",
  ["#rfenghou__Sylvanas"] = "黑暗女王",
  ["designer:rfenghou__Sylvanas"] = "换家德没有🐴",
  ["cv:rfenghou__Sylvanas"] = "",
  ["illustrator:rfenghou__Sylvanas"] = "Enshanlee_",
}

local anyingjiuxu = fk.CreateTriggerSkill{
  name = "rfenghou__anyingjiuxu",
  anim_type = "control",
  events = {fk.CardUseFinished},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.extra_data and data.extra_data.rfenghou__anyingjiuxu_card then
      return table.find(player.room.alive_players, function (p)
        return p ~= player and not p:hasSkill(self, true)
      end) ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function (p) return not p:hasSkill(self, true) end)
    if #targets == 0 then return false end
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
    "#rfenghou__anyingjiuxu-giveskill", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:setPlayerMark(to, "@@rfenghou__anyingjiuxu", 1)
    room:handleAddLoseSkills(to, self.name)
  end,

  refresh_events = {fk.PreCardUse, fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    if event == fk.PreCardUse then
      if player:hasSkill(self) and target == player then
        local cards = Card:getIdList(data.card)
        if #cards == 0 then return end
        local id = player.room.draw_pile[1]
        return id and table.contains(cards, id)
      end
    else
      return target == player and player:getMark("@@rfenghou__anyingjiuxu") ~= 0
      and data.extra_data and data.extra_data.rfenghou__anyingjiuxu_card
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.PreCardUse then
      player:broadcastSkillInvoke(self.name)
      player.room:notifySkillInvoked(player, self.name, "drawcard")
      data.extra_data = data.extra_data or {}
      data.extra_data.rfenghou__anyingjiuxu_card = true
    else
      player.room:setPlayerMark(player, "@@rfenghou__anyingjiuxu", 0)
      player.room:handleAddLoseSkills(player, "-"..self.name, nil, false, true)
    end
  end,

  dynamic_desc = function (self, player, lang)
    if player:getMark("@@rfenghou__anyingjiuxu") ~= 0 then
      return "rfenghou__anyingjiuxu_temp"
    end
    return self.name
  end,
}

local anyingjiuxu_filter = fk.CreateFilterSkill{
  name = "#rfenghou__anyingjiuxu_filter",
  card_filter = function(self, card, player)
    if player:hasSkill(anyingjiuxu) and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:hasSkill(anyingjiuxu, true)
    end) then
      return card.name == "jink"
    end
  end,
  view_as = function(self, card)
    local c = Fk:cloneCard("slash", card.suit, card.number)
    c.skillName = "rfenghou__anyingjiuxu"
    return c
  end,

  handly_cards = function (self, player)
    if player:hasSkill(anyingjiuxu) then
      local id = Fk:currentRoom().draw_pile[1]
      if id then
        return {id}
      end
    end
  end,
}
anyingjiuxu:addRelatedSkill(anyingjiuxu_filter)

Sylvanas:addSkill(anyingjiuxu)

Fk:loadTranslationTable{
  ["rfenghou__anyingjiuxu"] = "暗影救赎",
  [":rfenghou__anyingjiuxu"] = "①牌堆顶牌对你可见，且可使用或打出。②当你以此法使用牌结算后，可以令一名其他角色获得以此法使用牌时即失去的“暗影救赎”;"..
  "③若有其他角色拥有“暗影救赎”，你的【闪】均视为无次数限制的【杀】。",
  ["#rfenghou__anyingjiuxu_filter"] = "暗影救赎",
  ["#rfenghou__anyingjiuxu-giveskill"] = "你可以令一名其他角色获得一次性的“暗影救赎”",
  [":rfenghou__anyingjiuxu_temp"] = "①牌堆顶牌对你可见，且可使用或打出。②当你以此法使用牌时，失去此技能。③若有其他角色拥有“暗影救赎”，你的【闪】均视为无次数限制的【杀】。",
  ["@@rfenghou__anyingjiuxu"] = "暗影救赎",
}

local jingshenkongzhi = fk.CreateTriggerSkill{
  name = "rfenghou__jingshenkongzhi",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play and (not player:isNude())
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function (p) return not p:isNude() end)
    local tos, cards = room:askForChooseCardsAndPlayers(player, 1, 1, table.map(targets, Util.IdMapper),
    1, 1, ".", "#rfenghou__jingshenkongzhi-invoke", self.name, true)
    if #tos > 0 and #cards > 0 then
      self.cost_data = {tos = tos, cards = cards}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local mycid = self.cost_data.cards[1]
    local tocid = room:askForCard(to, 1, 1, true, self.name, false, nil, "#rfenghou__jingshenkongzhi-show")[1]
    player:showCards(mycid)
    to:showCards(tocid)
    local mycard, tocard = Fk:getCardById(mycid), Fk:getCardById(tocid)
    -- 耦
    if (tocard.trueName == "slash" and mycard.name == "jink")
    or (tocard.type == Card.TypeTrick and mycard.trueName == "nullification") then
      room:loseHp(to, 1, self.name)
      if table.contains(player:getCardIds("he"), mycid) then
        room:moveCardTo(mycid, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
      end
    else
      if not player.dead and table.contains(to:getCardIds("he"), tocid) then
        U.askForUseRealCard(room, player, {tocid}, tostring(Exppattern{ id = {tocid} }), self.name, "#rfenghou__jingshenkongzhi-use", 
        {bypass_times = true, expand_pile = {tocid}}, false)
      end
    end
  end,
}
Sylvanas:addSkill(jingshenkongzhi)

Fk:loadTranslationTable{
  ["rfenghou__jingshenkongzhi"] = "精神控制",
  [":rfenghou__jingshenkongzhi"] = "出牌阶段开始时，你可以与一名有手牌的其他角色同时展示一张牌，若其展示的牌可以被你展示的牌抵消，其失去1体力并将你展示的牌置于牌堆顶，否则你可以使用其展示的牌。",
  ["#rfenghou__jingshenkongzhi-invoke"] = "精神控制：选择一张牌和一个其他角色，与其同时展示一张牌",
  ["#rfenghou__jingshenkongzhi-show"] = "精神控制：请展示一张牌",
  ["#rfenghou__jingshenkongzhi-use"] = "精神控制：你可以使用此牌",
}

local zhaoe = General:new(extension, "rfenghou__zhaoe", "qun", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["rfenghou__zhaoe"] = "赵娥",
  ["#rfenghou__zhaoe"] = "",
  ["designer:rfenghou__zhaoe"] = "Nurture",
  ["cv:rfenghou__zhaoe"] = "",
  ["illustrator:rfenghou__zhaoe"] = "三国志大战",
  ["~rfenghou__zhaoe"] = "",
}

local cuixue = fk.CreateTriggerSkill{
  name = "rfenghou__cuixue",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart, fk.TurnEnd},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) or target ~= player then return false end
    if event == fk.TurnStart then
      return true
    else
      local cards = player:getCardIds("h")
      return #cards > 0 and table.every(cards, function(id) return Fk:getCardById(id).trueName == "slash" end)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      local choices = {"0", "1", "2"}
      local choice = room:askForChoice(player, choices, self.name, "#rfenghou__cuixue-choice")
      room:setPlayerMark(player, "@rfenghou__cuixue-turn", tostring(choice))
    else
      player:showCards(player:getCardIds("h"))
      local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
      if #targets == 0 then return false end
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#rfenghou__cuixue-damage", self.name, false)
      if #tos > 0 then
        room:damage { from = player, to = room:getPlayerById(tos[1]), damage = 1, skillName = self.name }
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return data.card.trueName == "slash" and player:getMark("@rfenghou__cuixue-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + tonumber(player:getMark("@rfenghou__cuixue-turn"))
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@rfenghou__cuixue-turn", 0)
  end,
}

--- 获取某牌占用的手牌上限
---@param player Player
---@param card Card
---@retun integer
local function getMaxCardsOccupied (player, card)
  local maxcard_skills = Fk:currentRoom().status_skills[MaxCardsSkill] or Util.DummyTable
  if table.find(maxcard_skills, function(skill)
    return skill:excludeFrom(player, card)
  end) then return 0 end
  -- 在此处修改卡牌占用手牌上限
  if player:getMark("@rfenghou__cuixue-turn") ~= 0 and card.trueName == "slash" then
    return tonumber(player:getMark("@rfenghou__cuixue-turn")) or 1
  end
  return 1
end

-- 模拟弃牌阶段
---@param player ServerPlayer
local function discardPhase(player)
  local room = player.room
  local limit = player:getMaxCards()
  local occupied = 0
  for _, id in ipairs(player:getCardIds(Player.Hand)) do
    occupied = occupied + getMaxCardsOccupied(player, Fk:getCardById(id))
  end
  local discardNum = occupied - limit
  if discardNum <= 0 then return end
  local canDiscards = table.filter(player:getCardIds(Player.Hand), function(id)
    return getMaxCardsOccupied(player, Fk:getCardById(id)) > 0 and not player:prohibitDiscard(id)
  end)
  if #canDiscards == 0 then return end
  local default = {}
  local tempNum = discardNum
  for _, id in ipairs(canDiscards) do
    table.insert(default, id)
    tempNum = tempNum - getMaxCardsOccupied(player, Fk:getCardById(id))
    if tempNum <= 0 then break end
  end
  if #default == 0 then return end
  if #default < #canDiscards then
    local _ , dat = room:askForUseActiveSkill(player, "rfenghou__discard_skill", "#rfenghou__discard_skill:::"..discardNum, false,
    {skillName = "phase_discard", discardNum = discardNum})
    if dat then
      default = dat.cards
    end
  end
  room:throwCard(default, "phase_discard", player, player)
end

local maxcard_occupied_trigger = fk.CreateTriggerSkill{
  name = "#maxcard_occupied_trigger",
  --global = true,
  priority = 0.001,
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    if target == player and player.phase == Player.Discard and not player:isKongcheng() then
      return player:getMark("@rfenghou__cuixue-turn") ~= 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    if player._phase_end then return end
    discardPhase(player)
    return true
  end,
}
cuixue:addRelatedSkill(maxcard_occupied_trigger)

local rfenghou__discard_skill = fk.CreateActiveSkill{
  name = "rfenghou__discard_skill",
  card_filter = function (self, to_select, cards, player)
    if not table.contains(player.player_cards[Player.Hand], to_select)
    or getMaxCardsOccupied(player, Fk:getCardById(to_select)) <= 0
    or player:prohibitDiscard(to_select) then return false end
    return not self:feasible({}, cards, player)
  end,
  target_filter = Util.FalseFunc,
  feasible = function (self, _, cards, player)
    local num = 0
    local discardNum = self.discardNum or 1
    for _, id in ipairs(cards) do
      num = num + getMaxCardsOccupied(player, Fk:getCardById(id))
    end
    return num >= discardNum
  end,
}
Fk:addSkill(rfenghou__discard_skill)

Fk:loadTranslationTable{
  ["#maxcard_occupied_trigger"] = "弃牌阶段",
  ["rfenghou__discard_skill"] = "弃牌",
  ["#rfenghou__discard_skill"] = "请弃置 %arg 张牌",
}

zhaoe:addSkill(cuixue)
Fk:loadTranslationTable{
  ["rfenghou__cuixue"] = "淬血",
  [":rfenghou__cuixue"] = "锁定技，回合开始时，你令本回合【杀】伤害基数和占用手牌上限改为(0-2)，手牌上限减等量；回合结束时，你展示均为【杀】的手牌并对一名其他角色造成1点伤害。",
  ["#rfenghou__cuixue-damage"] = "淬血：对一名其他角色造成1点伤害",
  ["@rfenghou__cuixue-turn"] = "淬血",
  ["#rfenghou__cuixue-choice"] = "淬血：请令本回合【杀】伤害基数和占用手牌上限改为上述一个数字！",
}

local suchou = fk.CreateTriggerSkill{
  name = "rfenghou__suchou",
  anim_type = "offensive",
  events = {fk.DamageCaused, fk.Damage, fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) or target ~= player then return false end
    local mark = player:getMark("rfenghou__suchou_tar")
    if event == fk.DamageCaused then
      return data.to.id == mark and data.damage < (data.to.hp + data.to.shield)
      and table.contains(player.player_skills, self) -- 防止虚拟技能没法删除
    elseif event == fk.Damage then
      return data.to.id == mark and player:isWounded()
    elseif event == fk.Damaged then
      mark = player.room:getPlayerById(mark)
      return mark and not mark.dead and not player:isNude()
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      return room:askForSkillInvoke(player, self.name, nil, "#rfenghou__suchou-damage:"..data.to.id.."::"..((data.to.hp + data.to.shield)))
    elseif event == fk.Damage then
      return true
    else
      local cards = room:askForCard(player, 1, 999, true, self.name, true, nil, "#rfenghou__suchou-recast")
      if #cards > 0 then
        self.cost_data = {cards = cards}
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      data.damage = (data.to.hp + data.to.shield)
      room:handleAddLoseSkills(player, "-"..self.name)
    elseif event == fk.Damage then
      room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
    else
      room:recastCard(self.cost_data.cards, player, self.name)
    end
  end,

  refresh_events = {fk.Damage},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local currentDamage = room.logic:getCurrentEvent():findParent(GameEvent.Damage, true)
    if not currentDamage then return end
    local lastDamage = room.logic:getActualDamageEvents(1, function(e)
      return e.data[1].from == player and e.id < currentDamage.id
    end, nil, 1)[1]
    if lastDamage then
      local mark = player:getMark("rfenghou__suchou_tar")
      local new = 0
      if lastDamage.data[1].to == data.to then
        new = data.to.id
      end
      if mark ~= new then
        room:doIndicate(player.id, {new})
        room:setPlayerMark(player, "rfenghou__suchou_tar", new)
        room:setPlayerMark(player, "@rfenghou__suchou", new == 0 and 0 or room:getPlayerById(new).general)
      end
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@rfenghou__suchou", 0)
  end,
}
zhaoe:addSkill(suchou)

Fk:loadTranslationTable{
  ["rfenghou__suchou"] = "夙雠",
  [":rfenghou__suchou"] = "你对一名角色连续造成：两次伤害后，回复1点体力；三次伤害时，可以将之改为致命伤害并失去此技能。若有满足前者的角色存活，你受到伤害后可以重铸任意张牌。",
  ["@rfenghou__suchou"] = "夙雠",
  ["#rfenghou__suchou-damage"] = "夙雠：你可以将对 %src 造成伤害改为 %arg 点，并失去“夙雠”",
  ["#rfenghou__suchou-recast"] = "夙雠：你可以重铸任意张牌",
}

local zhaoe2 = General:new(extension, "rfenghou2__zhaoe", "qun", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["rfenghou2__zhaoe"] = "赵娥",
  ["#rfenghou2__zhaoe"] = "",
  ["designer:rfenghou2__zhaoe"] = "yyuaN",
  ["illustrator:rfenghou2__zhaoe"] = "充电juju",
  ["~rfenghou2__zhaoe"] = "",
}

local zhaoeEventMap = {[fk.Damage] = "damage", [fk.CardEffecting] = "cancel", [fk.Deathed] = "death", [fk.EventPhaseStart] = "start"}

local function getZhaoeSkillDesc(skill, player, lang)
  local skillName = skill.name
  local mark = player:getMark(skillName.."_event")
  if type(mark) == "table" then
    local arg = ""
    for _, v in ipairs(mark) do
      arg = arg..Fk:translate("rfenghou__zhaoevent_"..v, lang).."，"
    end
    return skillName.."_dyn:"..arg
  end
  return skillName
end

---@param player ServerPlayer
local function zhaoeSkillTriggerable(skill, player, event, target, data)
  local mark = player:getTableMark(skill.name.."_event")
  if not table.contains(mark, zhaoeEventMap[event]) then return false end
  if event == fk.EventPhaseStart then
    return player.phase == Player.Start and target == player
  elseif event == fk.Damage then
    if target == player then
      local firstDamage = player.room.logic:getActualDamageEvents(1, function(e) return e.data[1].from == player end)[1]
      return firstDamage and firstDamage.data[1] == data
    end
  elseif event == fk.CardEffecting then
    -- 抵消牌时，注意，不能使用 CardEffectCancelledOut，fk.CardEffectFinished
    -- data.responseToEvent and data.responseToEvent.card and data.responseToEvent.isCancellOut
    return data.from == player.id and data.toCard
  elseif event == fk.Deathed then
    return true
  end
  return false
end

local zhizhu = fk.CreateTriggerSkill{
  name = "rfenghou__zhizhu",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.Damage, fk.CardEffecting, fk.Deathed},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    return zhaoeSkillTriggerable(self, player, event, target, data)
  end,
  on_cost = function (self, event, target, player, data)
    local use = U.askForUseRealCard(player.room, player, nil, nil, self.name, "#rfenghou__zhizhu-use",
    {bypass_distances = true, bypass_times = true}, true, true)
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local use = self.cost_data
    local room = player.room
    local num = #player:getTableMark("rfenghou__zhizhu_event")
    local tars = {}
    for _, p in ipairs(room.alive_players) do
      if p:getHandcardNum() < num then
        table.insert(tars, p.id)
      end
    end
    use.disresponsiveList = tars
    room:useCard(use)
    if use.card.trueName == "slash" and not use.damageDealt then
      local e = zhaoeEventMap[event]
      if e then
        room:removeTableMark(player, "rfenghou__zhizhu_event", e)
        room:addTableMarkIfNeed(player, "rfenghou__chouren_event", e)
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, self.name.."_event", {"start"})
  end,
  dynamic_desc = function (self, player, lang)
    return getZhaoeSkillDesc(self, player, lang)
  end,
}
zhaoe2:addSkill(zhizhu)

Fk:loadTranslationTable{
  ["rfenghou__zhizhu"] = "直诛",
  [":rfenghou__zhizhu"] = "准备阶段，你可以无次数距离限制地使用一张手牌，手牌数小于X的角色不能响应（X为“直诛”时机数）。若为【杀】且未造成伤害，将当前发动时机移动至“筹刃”。",
  [":rfenghou__zhizhu_dyn"] = "{1}你可以无次数距离限制地使用一张手牌，手牌数小于X的角色不能响应（X为“直诛”时机数）。若为【杀】且未造成伤害，将当前发动时机移动至“筹刃”。",
  ["#rfenghou__zhizhu-use"] = "直诛：你可以无次数距离限制地使用一张牌",

  ["rfenghou__zhaoevent_start"] = "准备阶段",
  ["rfenghou__zhaoevent_damage"] = "每回合首次造成伤害后",
  ["rfenghou__zhaoevent_cancel"] = "你抵消牌时",
  ["rfenghou__zhaoevent_death"] = "有角色死亡后",
}

local chouren = fk.CreateTriggerSkill{
  name = "rfenghou__chouren",
  events = {fk.EventPhaseStart, fk.Damage, fk.CardEffecting, fk.Deathed},
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) or player:getHandcardNum() == 4 then return false end
    return zhaoeSkillTriggerable(self, player, event, target, data)
  end,
  on_cost = function (self, event, target, player, data)
    local prompt = ""
    local x = player:getHandcardNum() - 4
    if x > 0 then
      prompt = "#rfenghou__chouren-discard:::"..x
    else
      x = -x
      local num = #player:getTableMark("rfenghou__zhizhu_event")
      if x > num then
        local e = zhaoeEventMap[event]
        e = e and ("rfenghou__zhaoevent_"..e) or "?"
        prompt = "#rfenghou__chouren-drawtrans:::"..x..":"..e
      else
        prompt = "#rfenghou__chouren-draw:::"..x
      end
    end
    return player.room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local x = player:getHandcardNum() - 4
    if x > 0 then
      room:askForDiscard(player, x, x, false, self.name, false)
    else
      local draw = player:drawCards(-x, self.name)
      if player.dead then return end
      local num = #player:getTableMark("rfenghou__zhizhu_event")
      if draw and #draw > num then
        local e = zhaoeEventMap[event]
        if e then
          room:removeTableMark(player, "rfenghou__chouren_event", e)
          room:addTableMarkIfNeed(player, "rfenghou__zhizhu_event", e)
        end
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, self.name.."_event", {"damage", "cancel", "death"})
  end,
  dynamic_desc = function (self, player, lang)
    return getZhaoeSkillDesc(self, player, lang)
  end,
}
zhaoe2:addSkill(chouren)

Fk:loadTranslationTable{
  ["rfenghou__chouren"] = "筹刃",
  [":rfenghou__chouren"] = "你每回合首次造成伤害后，你抵消牌时，有角色死亡后，你可以调整手牌数至4，若摸牌数大于X，将当前发动时机移动至“直诛”。",
  [":rfenghou__chouren_dyn"] = "{1}你可以调整手牌数至4，若摸牌数大于X，将当前发动时机移动至“直诛”。",
  ["#rfenghou__chouren-discard"] = "筹刃：你可以弃置 %arg 张手牌，然后无事发生",
  ["#rfenghou__chouren-draw"] = "筹刃：你可以摸 %arg 张牌",
  ["#rfenghou__chouren-drawtrans"] = "筹刃：你可以摸 %arg 张牌，且将时机（%arg2）移动至“直诛”",
}

local gaoyang = General:new(extension, "rfenghou__gaoyang", "qi", 4, 4, General.Male)
gaoyang.hidden = true

local jingshen = fk.CreateTriggerSkill{
  name = "rfenghou__jingshen",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local yangkuang = fk.CreateTriggerSkill{
  name = "rfenghou__yangkuang",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local shizhan = fk.CreateTriggerSkill{
  name = "rfenghou__shizhan",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
gaoyang:addSkill(jingshen)
gaoyang:addSkill(yangkuang)
gaoyang:addSkill(shizhan)
Fk:loadTranslationTable{
  ["rfenghou__gaoyang"] = "高洋",
  ["#rfenghou__gaoyang"] = "朝光暮血",
  ["designer:rfenghou__gaoyang"] = "屑",
  ["cv:rfenghou__gaoyang"] = "",
  ["illustrator:rfenghou__gaoyang"] = "王于兴师",
  ["~rfenghou__gaoyang"] = "",

  ["rfenghou__jingshen"] = "景深",
  [":rfenghou__jingshen"] = "你于使用一张牌后，可以将场上一张与之同类型牌向下家移动，若无法移动，则改为下下家；多次进入过你区域的牌可当任意基本牌使用，且三次进入后额外结算两次。",
  ["rfenghou__yangkuang"] = "佯狂",
  [":rfenghou__yangkuang"] = "锁定技，出牌阶段，你改为不断选择一项，直到不想选择：1.蓄谋一张黑色牌；2.将两张牌置于牌堆顶；3.将三张红色牌当【无中生有】使用；4.摸四张牌并失去一个技能。",
  ["rfenghou__shizhan"] = "试斩",
  [":rfenghou__shizhan"] = "主公技，任一角色死亡后，若死亡角色/击杀者为齐势力，你可以结束本阶段，或本回合，或本轮。",
}

local gaoyang2 = General:new(extension, "rfenghou2__gaoyang", "qi", 4, 4, General.Male)
gaoyang2.hidden = true

local jundeng = fk.CreateTriggerSkill{
  name = "rfenghou__jundeng",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local guozheng = fk.CreateTriggerSkill{
  name = "rfenghou__guozheng",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
local woshi = fk.CreateTriggerSkill{
  name = "rfenghou__woshi",
  frequency = Skill.Compulsory,
  can_trigger = Util.FalseFunc,
}
gaoyang2:addSkill(jundeng)
gaoyang2:addSkill(guozheng)
gaoyang2:addSkill(woshi)

Fk:loadTranslationTable{
  ["rfenghou2__gaoyang"] = "高洋",
  ["#rfenghou2__gaoyang"] = "金戈射虎",
  ["designer:rfenghou2__gaoyang"] = "君腾天下",
  ["cv:rfenghou2__gaoyang"] = "",
  ["illustrator:rfenghou2__gaoyang"] = "王于兴师",
  ["~rfenghou2__gaoyang"] = "",

  ["rfenghou__jundeng"] = "君登",
  [":rfenghou__jundeng"] = "隐匿技，锁定技，你登场时，当前回合角色视为使用一张【酒】；若此【酒】未生效，回合结束时其失去一点体力，你隐匿。",
  ["rfenghou__guozheng"] = "国整",
  [":rfenghou__guozheng"] = "一名角色的出牌阶段开始时，你可令其选择是否弃置一张【闪】并令你摸两张牌；若其选择否，你可观看其手牌，若其中：没【闪】，你本轮失去此技能；有【闪】，你可弃置其中所有并于本轮将你一个技能中的非【杀】牌名改为【杀】，然后隐匿。",
  ["rfenghou__woshi"] = "我弑",
  [":rfenghou__woshi"] = "主公技，齐势力角色死亡时，你可成为击杀者，然后观看所有角色的手牌并令一名手牌中有【桃】的角色代替你执行奖惩，最后登场。",
}

local xiaoyanl = General:new(extension, "rfenghou1__xiaoyan", "liang", 4)

local cunyue_evnts = {fk.RoundEnd, fk.RoundStart, fk.BeforeCardsMove}

local cunyue_choose = fk.CreateActiveSkill{
  name = "#rfenghou__cunyue_choose",
  can_use = Util.FalseFunc,
  interaction = function (self, player)
    return UI.ComboBox { choices = {"cunyue-move", "cunyue-divine"} }
  end,
  card_num = 0,
  target_num = function (self)
    return self.interaction.data == "cunyue-divine" and 0 or 2
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    if self.interaction.data == "cunyue-divine" then
      return false
    else
      if #selected == 0 then
        return true
      elseif #selected == 1 then
        local playerA = Fk:currentRoom():getPlayerById(selected[1])
        return table.find(playerA:getCardIds("ej"), function (id)
          return playerA:canMoveCardInBoardTo(Fk:currentRoom():getPlayerById(to_select), id)
        end)
      else
        return false
      end
    end
  end,
}
Fk:addSkill(cunyue_choose)

local cunyue = fk.CreateTriggerSkill{
  name = "rfenghou__cunyue",
  mute = true,
  frequency = Skill.Compulsory,
  events = cunyue_evnts,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      local index = table.indexOf(cunyue_evnts, event)
      return index and player:getTableMark("@rfenghou__cunyue")[index] == "×"
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event ~= fk.BeforeCardsMove then
      return true
    else
      local infos = {}
      for _, move in ipairs(data) do
        if move.from == player.id and move.proposer == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea < Card.PlayerEquip then
              table.insertIfNeed(infos, info)
            end
          end
        end
      end
      if #infos > 0 then
        self.cost_data = infos
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    if event == fk.RoundEnd then
      player.room:notifySkillInvoked(player, self.name, "drawcard")
      if player:getHandcardNum() < player:getMaxCards() then
        player:drawCards( (player:getMaxCards() - player:getHandcardNum()) )
      end
    elseif event == fk.RoundStart then
      player.room:notifySkillInvoked(player, self.name, "control")
      for i = 1, 3 do
        if player.dead then break end
        local _, ret = player.room:askForUseActiveSkill(player, "#rfenghou__cunyue_choose", "#rfenghou__cunyue-choose:::"..i, false)
        if ret then
          if ret.interaction == "cunyue-divine" then
            player.room:askForGuanxing(player, player.room:getNCards((4 - i)))
            break
          else
            local tagretA, tagretB = table.unpack(table.map(ret.targets, function(id) return player.room:getPlayerById(id) end))
            player.room:askForMoveCardInBoard(player, tagretA, tagretB, self.name, nil, tagretA)
          end
        end
      end
    else
      player.room:notifySkillInvoked(player, self.name, "support")
      local infos = table.simpleClone(self.cost_data)
      local cards = {}
      for _, move in ipairs(data) do
        if move.from == player.id and move.proposer == player.id and move.moveReason == fk.ReasonDiscard then
          for j = #infos, 1, -1 do
            if table.contains(infos, move.moveInfo[j]) then
              table.insertIfNeed(cards, move.moveInfo[j].cardId)
              table.remove(infos, j)
            end
          end
        end
      end
      player.room:askForYiji(
        player, cards, player.room:getOtherPlayers(player, false),
        self.name, #cards, #cards, "#rfenghou__cunyue-yiji"
      )
    end
  end,

  on_acquire = function (self, player)
    local marks = {"×", "×", "×"}
    if #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      return player:isKongcheng()
    end, Player.HistoryGame) == 1 then
      marks[1] = "√"
    end
    if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
      for _, use in ipairs(e.data) do
        if use.from == player.id and use.card.type == Card.TypeEquip then
          return true
        end
      end
    end, Player.HistoryGame) == 1 then
      marks[2] = "√"
    end
    if #player.room.logic:getEventsOfScope(GameEvent.Dying, 1, function (e)
      for _, dying in ipairs(e.data) do
        if dying.who == player.id then
          return true
        end
      end
    end, Player.HistoryGame) == 1 then
      marks[3] = "√"
    end
    player.room:setPlayerMark(player, "@rfenghou__cunyue", marks)
  end,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@rfenghou__cunyue", 0)
  end
}

local cunyue_mod = fk.CreateTargetModSkill{
  name = "#rfenghou__cunyue_mod",
  residue_func = function (self, player, skill, scope)
    if player:hasSkill(cunyue) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return #table.filter(player:getTableMark("@rfenghou__cunyue"), function (e)
        return e == "√"
      end)
    end
  end,
}
cunyue:addRelatedSkill(cunyue_mod)

local cunyue_delay = fk.CreateTriggerSkill{
  name = "#rfenghou__cunyue_delay",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(cunyue)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    data.num = data.num + #table.filter(player:getTableMark("@rfenghou__cunyue"), function (e)
      return e == "√"
    end)
  end,

  refresh_events = {fk.AfterCardsMove, fk.CardUsing, fk.EnterDying},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(cunyue) then
      if event == fk.AfterCardsMove then
        return player:isKongcheng()
      elseif event == fk.CardUsing then
        return player == target and data.card.type == Card.TypeEquip
      else
        return player == target
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local events = {fk.AfterCardsMove, fk.CardUsing, fk.EnterDying}
    local mark = player:getTableMark("@rfenghou__cunyue")
    mark[table.indexOf(events, event)] = "√"
    player.room:setPlayerMark(player, "@rfenghou__cunyue", mark)
  end
}
cunyue:addRelatedSkill(cunyue_delay)

xiaoyanl:addSkill(cunyue)

local fuding = fk.CreateTriggerSkill{
  name = "rfenghou__fuding",
  frequency = Skill.Limited,
  events = {fk.RoundEnd},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      local is_death, killer = false, {}
      player.room.logic:getEventsOfScope(GameEvent.Death, 999, function (e)
        is_death = true
        if e.data[1].damage and e.data[1].damage.from then
          if e.data[1].damage.from.kingdom == player.kingdom then
            table.insertIfNeed(killer, e.data[1].damage.from.id)
          end
        end
      end, Player.HistoryRound)
      if is_death then
        self.cost_data = killer
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local prompt
    if table.contains(self.cost_data, player.id) then
      prompt = "#rfenghou__fuding-ivk3"
    elseif #self.cost_data > 0 then
      prompt = "#rfenghou__fuding-ivk2"
    else
      prompt = "#rfenghou__fuding-ivk1"
    end
    self.cost_data = prompt
    return player.room:askForSkillInvoke(player, self.name, data, prompt)
  end,
  on_use = function (self, event, target, player, data)
    player:gainAnExtraTurn(true, self.name)
    if self.cost_data == "#rfenghou__fuding-ivk3" then
      if player:hasSkill(cunyue) then
        player.room:setPlayerMark(player, "@rfenghou__cunyue", {"×", "×", "x"})
      end
      player.room:handleAddLoseSkills(player, "-"..self.name)
      player.room:handleAddLoseSkills(player, self.name)
      player:setSkillUseHistory(self.name, 0, Player.HistoryGame)
    elseif self.cost_data == "#rfenghou__fuding-ivk2" then
      player.room:handleAddLoseSkills(player, "-"..self.name)
      if player.role == "lord" then
        player.room:handleAddLoseSkills(player, "rfenghou__fuding_lord")
      end
    end
  end,
}
xiaoyanl:addSkill(fuding)

local fuding_lord = fk.CreateTriggerSkill{
  name = "rfenghou__fuding_lord",
  frequency = Skill.Limited,
  events = {fk.RoundEnd},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(fuding.name, Player.HistoryGame) == 0 then
      local is_death, killer = false, {}
      player.room.logic:getEventsOfScope(GameEvent.Death, 999, function (e)
        is_death = true
        if e.data[1].damage and e.data[1].damage.from then
          if e.data[1].damage.from.kingdom == player.kingdom then
            table.insertIfNeed(killer, e.data[1].damage.from.id)
          end
        end
      end, Player.HistoryRound)
      if is_death then
        self.cost_data = killer
        return true
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local prompt
    if table.contains(self.cost_data, player.id) then
      prompt = "#rfenghou__fuding-ivk3"
    elseif #self.cost_data > 0 then
      prompt = "#rfenghou__fuding-ivk2"
    else
      prompt = "#rfenghou__fuding-ivk1"
    end
    self.cost_data = prompt
    return player.room:askForSkillInvoke(player, self.name, data, prompt)
  end,
  on_use = function (self, event, target, player, data)
    player:gainAnExtraTurn(true, self.name)
    if self.cost_data == "#rfenghou__fuding-ivk3" then
      if player:hasSkill(cunyue) then
        player.room:setPlayerMark(player, "@rfenghou__cunyue", {"×", "×", "x"})
      end
      player.room:handleAddLoseSkills(player, "-"..self.name)
      player.room:handleAddLoseSkills(player, fuding.name)
      player:setSkillUseHistory(fuding.name, 0, Player.HistoryGame)
    end
  end,
}
Fk:addSkill(fuding_lord)

Fk:loadTranslationTable{
  ["rfenghou1__xiaoyan"] = "萧衍",
  ["#rfenghou1__xiaoyan"] = "尘辇啸钺",
  ["designer:rfenghou1__xiaoyan"] = "燕知春雪",
  ["illustrator:rfenghou1__xiaoyan"] = "白菜头草帽",

  ["rfenghou__cunyue"] = "寸岳",
  [":rfenghou__cunyue"] = "锁定技，你未："
  .."失去所有手牌前，轮次结束便补满手牌；"
  .."装备装备牌前，轮次开始便依次移动场上牌与卜算共三；"
  .."进入濒死前，你的弃牌改为交出；"
  .."你已满足项额外为你提供等量摸牌阶段摸牌数与出【杀】次数。",

  ["#rfenghou__cunyue_choose"] = "寸岳",
  ["#rfenghou__cunyue_mod"] = "寸岳",
  ["#rfenghou__cunyue_delay"] = "寸岳",

  ["@rfenghou__cunyue"] = "寸岳",
  ["cunyue-divine"] = "寸岳·卜算",
  ["cunyue-move"] = "寸岳·移动",
  ["#rfenghou__cunyue-choose"] = "寸岳：移动场上牌与卜算共三（%arg/3）<br/>特殊处理：选择卜算会消耗所有剩余次数",
  ["#rfenghou__cunyue-yiji"] = "寸岳：请分配被弃置的牌",

  ["rfenghou__fuding"] = "覆鼎",
  [":rfenghou__fuding"] = "限定技，轮次结束时，若本轮存活角色数发生过变动，你可执行一个额外回合。然后若为与你同势力者杀死的，“覆鼎”改为主公技，但若为你杀死的，复原你的所有技能。",
  ["#rfenghou__fuding-ivk3"] = "覆鼎：可以执行一个额外回合，并复原你的所有技能。",
  ["#rfenghou__fuding-ivk2"] = "覆鼎：可以执行一个额外回合，并将此技能改为主公技",
  ["#rfenghou__fuding-ivk1"] = "覆鼎：可以执行一个额外回合",

  ["rfenghou__fuding_lord"] = "覆鼎",
  [":rfenghou__fuding_lord"] = "主公技，限定技，轮次结束时，若本轮存活角色数发生过变动，你可执行一个额外回合。然后若为与你同势力者杀死的，“覆鼎”改为主公技，但若为你杀死的，复原你的所有技能。",
}

return extension